2012-06-26 24 views

回答

1

我刚刚调整了你的代码

var CssLoader = (function(){ 
    var $=''; //the global $ inside CssLoader 
    function init($, cssPathArray){ // Receive the jquery in the first argument 
     $=jq; // assign jQuery to global $, so it'll be available inside CssLoader 
     alert($('body'));    
    } 

    return { 
     init : init 
    }; 
})(); 

而且内部函数调用mainCssLoader.init如下

CssLoader.init($, ['cssPath1', 'cssPath2']); // Pass the jquery in the first argument 

DEMO.

+0

谢谢。这将工作,但这将意味着我将不得不将jquery传递到我创建的每个对象(需要它)。我希望避免这种情况。 – Finnnn

+0

不,您应该首先调用init,以便它可以在全球范围内使用,但这是正确的方法,我只是稍微调整了一下代码。检查演示,有两个警报。不用谢! –

相关问题