2013-02-24 114 views
2

我有一個jQuery插件。其中一個選項是用於動畫的緩動方法。我希望能夠檢查是否定義了緩動方法,然後繼續並使用指定的緩動方法調用$.animate(...)函數。像這樣:如何檢查是否定義了特定的jquery-easing方法?

var easingMethod = option.easing; 
if (!IsDefined(easingMethod)) easingMethod = 'linear'; 

什麼是IsDefined()函數?

我可以做if (typeof(easingMethod)==undefined),但typeof(easingMethod)==='string'。我想更多的沿線

function isDefined(s) { 
    // If a method named 's' is defined, return true, else false 
} 

而我不知道該怎麼做。

回答

3

這個怎麼樣?

function isDefined(s) { 
    return $.easing.hasOwnProperty(s); 
} 
+0

感謝。這似乎工作。我應該準備好更多關於'hasOwnProperty(s)'的內容。 – 2013-02-24 11:04:33

相關問題