(function(){
//this is to access this a property "PublicItem" from outside this closure
window.PublicItem=function(){
//codes
}
//internal variables
var _varA,_varB,_varC,_varD;
//internal functions
function _internalFunc1(){}
function _internalFunc2(){}
function _internalFunc3(){}
})();
ケースB
(function(){
//this is to access this a property "PublicItem" from outside this closure
window.PublicItem=function(){
//codes
}
//this variable will hold all internal variables and methods
var _global={};
//internal variables to hold all other internal variables
_global._varA="something for a";
_global._varB="something for b";
_global._varC="something for c";
//internal functions
_global._internalFunc1=function(){}
_global._internalFunc2=function(){}
_global._internalFunc3=function(){}
})();
2例との違いは、場合、私は、必要があるとして、私は、変数/関数などの多くのように作成したです。そしてcase2私は_global
という名前の単一の変数を作成しました。内部変数/関数を作成するためには、_global
というプロパティを作成しました。私はあなたに、メモリとパフォーマンスの面で特別に優れた方法を教えてください。他のパラメータについてもコメントすることができます。
oopsはちょっとした間違いを修正しました。 –
あなたの無名関数式は構文的に間違っています。 '(function(){/ * ... code here ... * /})();' –
@andyと@felixのようになります。 –