鍍金池/ 問答/HTML/ 為什么有時候使用toFixed會出錯

為什么有時候使用toFixed會出錯

var a=1100.22222;
return a.toFixed(2);

vue.js:584 [Vue warn]: Error in render: "TypeError: a.toFixed is not a function"

回答
編輯回答
風清揚

之前用 Anglar 碰到過相似的問題,當時是因為有人重寫了原型方法。

2018年3月29日 00:17
編輯回答
情皺

完整代碼看一下,這是開發(fā)模式還是生產(chǎn)模式

2017年6月24日 04:38
編輯回答
司令

我在想,是否某地方重寫了 Number.prototype.toFixed ?

// ... 假設哪個天殺的做了這件件蠢事?
Number.prototype.toFixed = null;
// ...

var a = 1100.22222; 
console.log(Number.prototype.toFixed); // 作為測試,可以打印看看結果。
a.toFixed(2); // 報同樣的錯誤。
2018年1月19日 10:03