// namespace 패턴
var myApp = myApp || {}; // 네임 스페이스 선언
myApp.insanehong = function () {
return "insanehong";
};
myApp.helloworld = function () {
return "hello world";
};
// 모듈 페턴
var Messages = { h: "hello", w: "world", insane: "insanehong" };
var myApp = (function (msg) {
var helloworld = msg.h + " " + msg.w;
var helloinsanehong = msg.h + " " + msg.insane;
var printInsane = function () {
return helloinsanehong;
};
var printhello = function () {
return helloworld;
};
return {
foo1: printInsane,
foo2: printhello,
};
})(Messages);
console.log(myApp.foo1());
console.log(myApp.helloworld);
'FRONT > JAVASCRIPT' 카테고리의 다른 글
[Javascript] 알고리즘-등수 구하기 (0) | 2022.04.01 |
---|---|
[Javascript] 알고리즘-점수 계산 (0) | 2022.03.30 |
[Javascript] 알고리즘-가위바위보 (0) | 2022.03.29 |
[Javascript] 알고리즘-보이는 학생 (0) | 2022.03.28 |
[Javascript] 알고리즘-큰 수 출력하기 (0) | 2022.03.28 |