RESOLVED DUPLICATE of bug 152706 145155
ES6 classes: Subclassing arrays doesn't work
https://bugs.webkit.org/show_bug.cgi?id=145155
Summary ES6 classes: Subclassing arrays doesn't work
Nikita Vasilyev
Reported 2015-05-18 17:48:56 PDT
var MyArray = class MyArray extends Array { constructor(len) { super(len); } myMethod() {} }; var myArr = new MyArray(0); console.log(myArr.myMethod); // 'function' in Chrome 42+, undefined in WebKit ToT console.log(myArr instanceof MyArray); // true in Chrome 42+, false in WebKit ToT myArr.push(1); console.log(myArr instanceof MyArray); // true in Chrome 42+, false in WebKit ToT
Attachments
Richard Connamacher
Comment 1 2015-12-02 11:13:57 PST
WebKit isn't setting the right prototype chain when instantiating an Array subclass. Because of this, the following workaround restores the correct behavior in the WebKit nightly: var MyArray = class MyArray extends Array { constructor() { super(...arguments); Object.setPrototypeOf(this, new.target.prototype); } myMethod() {} };
Richard Connamacher
Comment 2 2016-01-08 13:39:57 PST
This appears to have been fixed in the latest WebKit nightly (as of 1/8/2016)
Alexey Shvayka
Comment 3 2020-03-10 15:31:31 PDT
Fixed in https://trac.webkit.org/changeset/194612. Tests: JSTests/ChakraCore/test/es6/classes.js JSTests/ChakraCore/test/es6/ES6SubclassableBuiltins.js JSTests/es6/Array_is_subclassable_*.js JSTests/test262/test/language/statements/class/subclass/builtin-objects/Array/*.js *** This bug has been marked as a duplicate of bug 152706 ***
Note You need to log in before you can comment on or make changes to this bug.