I came across a javascript / jQuery design framework where every action was defined in an object literal, for example:
if(typeof window.MYWEB === "undefined"){
window.MYWEB = {};
}
MYWEB.Utils = {
doSthgUsingWinSize: function(){
var width = $(window).width();
},
doSthgElseUsingWinSize: function(){
var width = $(window).width();
}
};
$(document).ready(function(){
window.MYWEB.Utils.doSthgUsingWinSize();
window.MYWEB.Utils.doSthgElseUsingWinSize();
});
First question: Is this a form of a “module design pattern”? (Wherever I get interested in examples of module templates, there are anonymous functions and IIFE, and I'm confused about what the module template does).
: var width = $(window).width() . "", , $(window).width() , 2 ? - . (edit: , $(window).width() - ):
MYWEB.Utils = {
_getWindowWidth: function(){
return $(window).width();
},
doSthgUsingWinSize: function(){
var width = MYWEB.Utils._getWindowWidth();
},
etc
}
, - , Google!
.