JavaScript Patterns
1. Module & Revealing Module pattern
// STANDARD MODULE PATTERN - private/public variable
const UICtrl = (function () {
let text = "Hello world";
const changeText = function () {
const element = document.querySelector("h1");
element.textContent = text;
};
// public which is accessible from outside
return {
callChangeText: function () {
changeText();
console.log(text);
},
};
})();
UICtrl.callChangeText();
2. Singleton pattern
it can only return one instance of an object at a time
3. Factory pattern
Creating an interface for creating objects
MVC Pattern
It is consist of with following Model, View, Controller.
Model take responsibility for data(application info) like data structure.
View represent for UI.
Controller is like a bridge between Model and View. They don't know each other. So it does monitor the change of Model and view like when event happens.
Comments
Post a Comment