2014-04-11 13 views
0

我創建匿名功能的JavaScript對象,這樣JavaScript的匿名自動執行與參數

(function(){ 
    window['d'] = this; 
    this.sayHello = function(){ 
    console.log("hello world"); 
    } 
})(); 

如何傳遞參數給d對象,這樣我可以把它像d(SOMEPARAMS).sayHello()也可以d.sayHello()被調用。需要改變什麼以及在哪裏?

+0

你認爲'd'是什麼? 'd'只是一個對象。 – thefourtheye

+0

那麼,我如何使jQuery的功能? '$()。something()'或'$ .something()'? –

+0

'$'實際上是一個函數對象,'something'只是該函數對象的一個​​屬性。 – thefourtheye

回答

0
(function(){ 
    var pars = arguments[0] || {}; 
    window['d'] = this; 
    this.sayHello = function(){ 
    console.log("hello world"); 
    } 
})({a:'test'})