티스토리 뷰
//네임스페이 정의
if (typeof (CompanyName) === 'undefined') {
CompanyName = {};
}
//네임스페이스 App이름
CompanyName.AppName = (function ($) {
// 변수의 연속 선언
var _first = function () {
// Important to always start with "var"
},
_second = function () {
// Chained ( ...}, ) so it doesnt need "var"
},
_third = "Just a var", // Variables just ends with ,
_four = "Another var"; // Closing the chain with ;
var _anotherFirst = function () {
// Previous chain of var's was ended with ; so this var needed "var" in order to start.
};
g_globalVar = "I'm free!"; // 전역 변수 .. 어디서든 동작
g_globalMethod = function () {
alert("I'm free too!"); // 전역 함수 .. 어디서든 동작
};
g_chainedGlobalVarOne = "We are free!",
g_chainedGlobalVarTwo = "We are free!";
// private 변수 .
var _privateVar = "privateVar: accessed from within AppLaunch.Admin namespace";
// private 메서드.
var _privateMethod = function () {
log("privateMethod: accessed only from within AppLaunch.Admin");
}; // Last variable in a chain must always end with ; before the return {}
function log() {
if (window.console && window.console.log)
window.console.log('[AppName] ' + Array.prototype.join.call(arguments, ' '));
};
return {
init: function () {
// Calling private
_privateMethod();
// Calling Public
this.myPublicMethod();
// Also Calling Public
CompanyName.AppName.myPublicMethod();
// Calling Other namespace's Public Method (when exists)
//CompanyName.OtherNamespace.externalPublicMethod();
},
// Public
myPublicMethod: function() {
log("myPublicMethod");
},
// In a View (MVC), I could have a page called myPage where I want to init
// some particular functions. myPage can be called just like init.
myPage: function() {
_second();
_third();
}
}
})(jQuery);
// Initialize
jQuery().ready(function() {
CompanyName.AppName.init()
CompanyName.AppName.myPublicMethod();
});
'웹개발 > Jquery' 카테고리의 다른 글
| jquery.Callback 소개 (0) | 2012.05.09 |
|---|---|
| jquery xml 를 ie가 파싱 못할 경우 . (0) | 2012.03.15 |
| my jQuery Plugin Module Patten Sample (0) | 2012.03.12 |
| jQuery Custom Event Sample (0) | 2012.03.06 |
| animate 페이드 하면서 움직이는 이중 효과 (0) | 2012.02.02 |
댓글