MDN文档指路:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed
规范指路:https://tc39.es/ecma262/#sec-number.prototype.tofixed
The toFixed() method formats a number using fixed-point notation.
1 | var numObj = 12345.6789; |
Exceptions RangeError If digits is too small or too large. Values between 0 and 100, inclusive, will not cause a RangeError. Implementations are allowed to support larger and smaller values as chosen. TypeError If this method is invoked on an object that is not a Number.
我们可以看到1.toFixed();
报的是SyntaxError
1 | 1..toFixed() |
改成上面三种形式皆可
V8如何处理toFixed的呢