我正在處理一些使用jQuery Countdown plugin的代碼。該插件允許一個回調函數傳遞當倒數降爲零,這將被執行:
{
until: new Date(remaining),
onExpiry: runSomeAction
}
runSomeAction
使用$(this)
拿起擊中計時器從0。我想換runSomeAction
,但我知道如何做到這一點的唯一方法是將paramenter添加到它,就像這樣:
{
until: new Date(remaining),
onExpiry: function() {
// my logic here...
runSomeAction($(this));
}
}
但現在我必須要改變的參數名稱runSomeAction
所有$(this)
引用。
有沒有辦法將runSomeAction
換成$(this)
而我不必改變它?
那麼在'runSomeAction'調用中['this' value](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/this)應該是什麼,你的倒數對象文字?來自'onExpiry'回調的'this'? – Bergi 2013-05-02 23:24:32