What I'd really like to have in the language is the ability to store a
property access into a single binding:

```
let someObj = { doStuff(){} };

let doStuff = #someObj.doStuff;

doStuff();
```
Treated as:
```
let someObj = { doStuff(){} };

someObj.doStuff();
```
- works with any property access
- could help simplify some existing code bases:
https://github.com/polymer/observe-js#path-objects
- for functions it would allow call/apply or bind to still work if needed

Now I realize this feature is more than syntactic sugar and would have to
work more like expression pointers but I can't see how the machinery of
this would need to be that much different than something like module
bindings.



- Matthew Robb

On Mon, Jul 13, 2015 at 11:02 AM, Brendan Eich <bren...@mozilla.org> wrote:

> 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@mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to