【发布时间】:2016-03-24 15:13:23
【问题描述】:
下面的代码在 Chrome V8 中记录为 false,但在 Babel 中记录为 true。 feedback from Google 说记录 false 是应该的,而记录 true 是 Babel 的错误。我查看了 ES6 规范,但仍然无法理解其背后的机制。任何想法将不胜感激!
class NewObj extends Object{
constructor(){
super(...arguments); // In V8, after arguments === [{attr: true}]
// is passed as parameter to super(),
// this === NewObj{} in V8;
// but this === NewObj{attr: true} in Babel.
}
}
var o = new NewObj({attr: true});
console.log(o.attr === true);
【问题讨论】:
-
我不明白对那个错误的反应;
super()调用肯定允许包含参数列表,并且 Object 构造函数应该注意它的参数。 -
这是一个 Chromium 错误。我已经在 Microsoft Edge 上进行了测试。它返回
true。
标签: javascript google-chrome ecmascript-6 v8 babeljs