Instance bound class methods
Brendan Eich
brendan at mozilla.org
Mon Jul 13 15:02:59 UTC 2015
You're counting on the property assignment being moved into the
constructor, where `this` is bound. In a class body in ES6 (without
property assignment extension), especially in the top level where method
defintiions go, `this` isn't obviously bound to the newly constructed
instance.
Ok, that's kind of a nit, or an observation. No worries.
Bigger question is what we want: method per instance allocation cost,
which what you did imposes? Or something that can be more efficiently
implemented, such as what Strong/SoundScript proposes (last I looked).
The latter is what Java and C++ do. Then the trick is enabling
first-class function extraction from method, which is a
pay-for-what-you-ask-for alternative to allocation per method per
constructed instance.
/be
Matthew Robb wrote:
> Are there any proposals or any discussions around solving the problem
> of instance bound class methods with some sugar?
>
> There are examples of people doing things like this:
> https://github.com/reactjs/react-future/blob/master/01%20-%20Core/01%20-%20Classes.js#L31
>
> My proposal would be to extend method shorthand syntax to support the
> arrow:
>
> ```
> class A extends React.Component {
> handleClick(event)=> {
> ...
> }
> }
> ```
> Which would be sugar for:
> ```
> class A extends React.Component {
> handleClick = (event)=> {
> ...
> }
> }
> ```
> - Matthew Robb
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
More information about the es-discuss
mailing list