super() does not work properly in a class extended from Object
Reported by
wenchong...@gmail.com,
Mar 24 2016
|
|||
Issue description
Chrome Version : 49.0.2623.87, 51.0.2683.0
URLs (if applicable) :
Other browsers tested:
Add OK or FAIL, along with the version, after other browsers where you
have tested this issue:
Safari:
Firefox:
IE:
What steps will reproduce the problem?
(1)Open the console panel
(2)type in:
class NewObj extends Object{
constructor(){
super(...arguments);
}
}
var o = new NewObj({attr: true});
console.log(o.attr === true);
(3)enter
What is the expected result?
true (according to ECMAScript 6 and Babel v6.x)
What happens instead?
false
Please provide any additional information below. Attach a screenshot if
possible.
,
Mar 24 2016
Why would this be a Babel bug? The constructor is passing arguments via a super() call, which seems like it should work and which is certainly allowed in the spec.
,
Mar 25 2016
See 19.1.1.1-1 https://tc39.github.io/ecma262/#sec-object-value: If NewTarget is neither undefined nor the active function, then Return ? OrdinaryCreateFromConstructor(NewTarget, "%ObjectPrototype%"). This says when Object is used as a super class, the argument `{attr: true}` would be completely ignored, instead, `Object.create(NewObj.prototype)` is returned, so `o.attr` would be undefined. For the same reason, `Reflect.construct(Object,[{attr:true}],function subclass(){}).attr` is undefined.
,
Mar 30 2016
,
Mar 30 2016
|
|||
►
Sign in to add a comment |
|||
Comment 1 by l446240525@gmail.com
, Mar 24 2016