相關錯誤:number is not a function, object is not a function, string is not a function, Unhandled Error: ‘foo’ is not a function, Function Expected
當嘗試調用一個像方法的值時,這個值并不是一個方法。比如:
1
2
var foo = undefined;
foo();
</tr>
</tbody>
</table>
如果你嘗試調用一個對象的方法時,你輸錯了名字,這個典型的錯誤很容易發生。
1
var x = document.getElementByID('foo');
</tr>
</tbody>
</table>
由于對象的屬性不存在,默認是undefined,以上代碼將導致這個錯誤。
嘗試調用一個像方法的數字,“number is not a function” 錯誤出現。
如何修復錯誤:確保方法名正確。這個錯誤的行號將指出正確的位置。
Uncaught ReferenceError: Invalid left-hand side in assignment
相關錯誤:Uncaught exception: ReferenceError: Cannot assign to ‘functionCall()’, Uncaught exception: ReferenceError: Cannot assign to ‘this’
嘗試給不能賦值的東西賦值,引起這個錯誤。
這個錯誤最常見的例子出現在 if 語句使用:
1
if(doSomething() = 'somevalue')
</tr>
</tbody>
</table>
此例中,程序員意外地使用了單個等號,而不是雙等號。“left-hand side in assignment” 提及了等號左手邊的部分,因此你可以看到以上例子,左手邊包含不能賦值的東西,導致這個錯誤。
如何修復錯誤:確保沒有給函數結果賦值,或者給this關鍵字賦值。
Uncaught TypeError: Converting circular structure to JSON
相關錯誤:Uncaught exception: TypeError: JSON.stringify: Not an acyclic Object, TypeError: cyclic object value, Circular reference in value argument not supported
把循環引用的對象,傳給JSON.stringify總會引起錯誤。
1
2
3
4
var a = { }; var b = { a: a };
a.b = b; JSON.stringify(a);