私は、インライン関数呼び出しでラッピングコードを理解している間、私ははっきりと変数のスコープを定義することができ、私はインライン関数呼び出しのメリットは何ですか?
のメリットを理解していない(function(window,undefined){
var jQuery=(function(){
var jQuery=something;
jQuery.xxx=xxx;
//...
return jQuery;
})();
//...
window.jQuery=window.$=jQuery;
})(window);
(expliclyそれは修正して、jQueryのであります)このコードを見て
- パラメータで
window
を渡す代わりに、それを直接使用して、 - は未定義パラメータによって
undefined
のインスタンスを取得し、また、 - 0を定義しますに、別のインライン関数呼び出しの戻り値を指定します。 誰かが少し説明できますか?
より明確EDIT書き込み#3:
私は理解してどのようなコードはそれを返し、その後、別の関数内jQuery
定義していることです。
//(function(window,undefined){
var jQuery=(function(){
// Inside this function defines jQuery and return it?
var jQuery=function(selector,context){
return new jQuery(selector,context); //simplified
};
jQuery.xxx=xxx;
//...
return jQuery;
})(); // This executes the inline function and assign `jQuery` with the return value???
//... })(window);
これは、次のようなより多くです:
//(function(window,undefined){
var jQuery=function(selector,context){
return new jQuery(selector,context); //simplified
};
jQuery.xxx=xxx;
//...
//... })(window);
日立、http://ejohn.org/apps/workshop/adv-talk/#31 **および** http://www.bennadel.com/blog/1838-Wrapping-The-Window-Object- In-A-jQuery-Wrapper.htmが役立つはずです! ':)' –