The `super` keyword doesn't work as it should?
Claude Pache
claude.pache at gmail.com
Thu Jul 21 10:21:21 UTC 2016
There is probably no way to make the `super` semantics just work in all use cases. But I think that the choice made in ES6 is the right one in order to have it correctly working in the most naïve (and maybe the most common?) use cases of method borrowing, i.e., when you don’t have knowledge of — or even you wilfully ignore — its implementation details. Consider for example:
```js
class MyArray extends Array {
forEach(callback, thisArg) {
// ...
super.forEach(callback, thisArg)
// ...
}
}
```
and somewhere else:
```js
NodeList.prototype.forEach = MyArray.prototype.forEach // or: (new MyArray).forEach
HTMLCollection.prototype.forEach = MyArray.prototype.forEach
```
Here, I expect that `super.forEach` will continue to point to `Array.prototype.forEach`. This is because I’m thinking of `MyArray.prototype.forEach` as a black box that should not change its behaviour just because I’m moving it around, as it is generally the case with methods of the builtin library.
—Claude
More information about the es-discuss
mailing list