2016-04-12 23 views
0

有沒有辦法在插件回調中添加多個方法?例如假設有這樣的插件,允許通過「afterInit」回調插件回調的多種方法

$("div.block-20").myPlugin({ 
    afterInit : method1 
}); 

現在我想運行其他方法(方法2)太調用一個方法。無論如何做到這一點沒有調整插件或合併2方法(method1,method2)?

+0

這個答案是正確的你:http://stackoverflow.com/a/4096550/6166191 –

回答

1

您可以使用匿名函數作爲回調函數:

$("div.block-20").myPlugin({ 
    afterInit : function() { 
     method1(); 
     method2(); 
     // do something other 
    } 
});