-1
我一直在試圖弄清楚爲什麼我的代碼中的這個特定的行不斷說'未定義不是函數'。 Associated Plunker「未定義不是函數」錯誤什麼是引用定義
// This line displays the function to be invoked
console.log((compileStrategies[tAttr.bsFormItem] || noop))
// This line displays that the bitwise selection is really a function
console.log(angular.isFunction(compileStrategies[tAttr.bsFormItem] || noop))
// Invocation with context that displays 'undefined is not a function'
(compileStrategies[tAttr.bsFormItem] || noop).apply(this, arguments)
我只是困惑,爲什麼它表明錯誤時明確按位選擇結果的功能。我知道我可以檢查compileStrategies[tAttr.bsFormItem]
是否已定義,然後調用它,但這個問題真的讓我感到困擾。如果有人能夠揭示這個謎,我會非常感激。
更新:
另一個奇怪behvaiour是當你將調用變量或返回它,它不會顯示「未定義是不是一個函數」錯誤了。
例如
var fn = (compileStrategies[tAttr.bsFormItem] || noop).apply(this, arguments)
或
return (compileStrategies[tAttr.bsFormItem] || noop).apply(this, arguments)
謝謝..我想通了像5分鐘前,我已經閱讀了有關自動分號插入JavaScript中的解釋@ http://bclary.com/2004/11/07/#a-7.9。 – ryeballar