zer*_*kms 6 javascript ecmascript-5
伙计们,我DO知道为什么10..toString()的工作,但10.toString()不?问题存在,但问题是它没有提供正式的解释.
规范的解释.该特定位置的字符是小数.这由ECMAScript的数字文字语法定义.
没有参考标准是不够可信的
我下意识地明白了
42..toString()
Run Code Online (Sandbox Code Playgroud)
解析器将其视为一个42.数字,然后是一个.toString()调用.
我无法理解的是为什么翻译无法实现这一点
42.toString()
Run Code Online (Sandbox Code Playgroud)
是一个42接着一个方法调用.
它只是现代JS解释器的缺点还是由ES5.1明确说明?
从ES5.1开始,Numeric Literal被定义为(仅是定义的重要部分):
NumericLiteral ::
DecimalLiteral
HexIntegerLiteral
DecimalLiteral ::
DecimalIntegerLiteral . DecimalDigits(opt) ExponentPart(opt)
. DecimalDigits ExponentPart(opt)
DecimalIntegerLiteral ExponentPart(opt)
Run Code Online (Sandbox Code Playgroud)
最后一条规则是我希望解析器选择的规则.
UPD:澄清一下,这个问题希望作为ES规范的答案参考,明确说明解释器必须像它一样行事
| 归档时间: |
|
| 查看次数: |
588 次 |
| 最近记录: |