Renki Ivanko (2016-05-03T23:21:09.000Z)
fatalis.erratum at gmail.com (2016-05-03T23:29:15.549Z)
It's currently impossible to inherit the behavior of exotic builtin objects like `Array` without using the `class extends` syntax, which is surprising to someone who has only seen the `class` syntax described as syntactical sugar for prototypal inheritance, since it means that the `class extends` syntax can't be fully desugared to the non-`class` syntax. It means that describing the `class` syntax as syntactical sugar should be qualified to be fully accurate (since trying to desugar it with, for example, Babel can potentially break things even in browsers that otherwise support native subclassing), and that non-`class` syntax is a second-class citizen in the language. Adding a method for using the native subclassing without the `class extends` syntax would be consistent with ES5 adding `Object.create()` that allows using prototypal inheritance without the `new` operator. The new method could be called `Object.inherits()`; a simplified example of how it could be used: ``` class Foo extends Array {} // ...desugars to function Foo() { function Foo(...args) { return Object.getPrototypeOf(Foo)(...args) } Object.inherits(Foo, Array) return Foo } Object.inherits = function(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype, { constructor: {value: subClass}, [Symbol.species]: {value: subClass}, }) Object.setPrototypeOf(subClass, superClass) // make subClass imbue the objects it constructs with native exotic behavior here }```
fatalis.erratum at gmail.com (2016-05-03T23:25:26.772Z)
It's currently impossible to inherit the behavior of exotic builtin objects like `Array` without using the `class extends` syntax, which is surprising to someone who has only seen the `class` syntax described as syntactical sugar for prototypal inheritance, since it means that the `class extends` syntax can't be fully desugared to the non-`class` syntax. It means that describing the `class` syntax as syntactical sugar should be qualified to be fully accurate (since trying to desugar it with, for example, Babel can potentially break things even in browsers that otherwise support native subclassing), and that non-`class` syntax is a second-class citizen in the language. Adding a method for using the native subclassing without the `class extends` syntax would be consistent with ES5 adding `Object.create()` that allows using prototypal inheritance without the `new` operator. The new method could be called `Object.inherits()`; a simplified example of how it could be used: ``` class Foo extends Array() {} // ...desugars to function Foo() { function Foo(...args) { return Object.getPrototypeOf(Foo)(...args) } Object.inherits(Foo, Array) return Foo } Object.inherits = function(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype, { constructor: {value: subClass}, [Symbol.species]: {value: subClass}, }) Object.setPrototypeOf(subClass, superClass) // make subClass imbue the objects it constructs with native exotic behavior here }```