Skip to main content

JavaScript Patterns, including MVC

 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

Popular posts from this blog

[BAEKJOON Online Judge + Node.js] 2292: Honeycomb

  I did't use while loop that much so didn't come up what to do. While loop create a loop that execute a specific statement. So, the main point of this problem is "prevNum + max * 6" input = 13, output = 3 https://www.acmicpc.net/problem/2292 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while const input = require ( "fs" ). readFileSync ( "/dev/stdin" ). toString () ; let count = 1 ; let max = 1 ; // set the range while (max < input) { max += count * 6 ; count ++ ; } console . log (count) ; // prevNum + count * 6 // 1 so +6 every loop! // 2 - 7, 5 // 8 - 19, 11 // 20 - 37, 17 // 38 - 61, 23

FE WebDev Routine Training Feb 09, 2021

 FE WebDev Routine Training Feb 09, 2021  A lot of things to do. DO FUCKING FOCUS!!!  Coding test - codewar 1 Kakao 2021 No.1 CSS - grid/ SCSS and Cloning(besthorrorscenes.com) JS - for of loop/  Sec9/ DOM array methods toy project React -   A bit of Yelp Portfolio -  List the 100JS projects Job hunting -  NAVER Finance(on 10th) Karrot for  internship  Apply SW maestro