Le 2 févr. 2014 à 23:27, Allen Wirfs-Brock <[email protected]> a écrit :
> I made the change in rev 22 to make the default constructor: return > super(...args) > > However that resulted in this bug: > https://bugs.ecmascript.org/show_bug.cgi?id=2491 from Arv: > >> The problem arises when we extend an old school "class" where the code does >> not >> explicitly set constructor. >> >> function B() {} >> B.prototype = { ... } >> class C extends B {} >> new C() instanceof C // false >> >> The reason why this fails is that `B.prototype.constructor === Object` so >> `new >> C()` returns `Object()`. >> >> The work around is to set `B.prototype.constructor = B` but I feel like the >> problem, adding return added solved, is smaller than the problem it >> introduces. > > I'm inclined to agree with Arv's conclusion. What do you think? > > Allen I think that this bug is indeed a good reason to use `super(...arguments)` instead of `return super(...arguments)`. However, I am slightly worried that, with the ES6 class syntax, the `constructor` method looks like a regular method, but it behaves differently w.r.t. inheritance. So, nonstandard uses of this method (wmay mysteriously fail when used on a super-class. Therefore, it would be nice if `return expression` would be statically forbidden in the `constructor` method when defined using the `class` syntax (but a bare `return` is fine, which slightly complicates the grammar). —Claude _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

