Re: `this`: methods versus functions

2011-11-10 Thread Axel Rauschmayer
Clever (took me a moment to figure out what the comma operator does here...). And makes sense: You would not want an invoker to have that kind of power. If it wasn’t so negative for performance, I probably would apply curryThis() to all of my methods: var obj = { method: function

Re: `this`: methods versus functions

2011-11-10 Thread Andreas Rossberg
On 10 November 2011 14:49, Axel Rauschmayer a...@rauschma.de wrote: getX() is designed for a dynamic `this` (i.e. `this` is an instance of InnerPoint). My proposal would allow an external party to switch to lexical `this` (=== function Outer), simply by invoking it as a (non-method) function.

Re: `this`: methods versus functions

2011-11-10 Thread Axel Rauschmayer
Any suggestion for improvement is highly welcome. But it seems like we can’t do better than a construct that declares statically, how its `this` should be passed to it. The cool thing about block lambdas is that you do the right thing without thinking about it. That’s why, if we got arrow

Re: `this`: methods versus functions

2011-11-10 Thread Axel Rauschmayer
I wonder if it made a difference if `this`was always stored in an environment (instead of an execution context). Then block lambdas could find them via the scope chain. If I understand you correctly, then yes, this is definitely possible in principle, and in fact corresponds to the standard

Re: `this`: methods versus functions

2011-11-10 Thread Andreas Rossberg
On 10 November 2011 15:58, Axel Rauschmayer a...@rauschma.de wrote: I wonder if it made a difference if `this`was always stored in an environment (instead of an execution context). Then block lambdas could find them via the scope chain. If I understand you correctly, then yes, this is

What do we still need from a class-like abstraction (was: `this`: methods versus functions)

2011-11-10 Thread Mark S. Miller
Note that the traitsjs library provides: 1) all the safety of the objects-as-closure pattern you show below (and more because it takes care of the needed freezing). 2) still allows intuitive use of this to refer to the instance itself, bound not lexically, but rather at object instantiation time.

Re: What do we still need from a class-like abstraction (was: `this`: methods versus functions)

2011-11-10 Thread Andreas Rossberg
I wholeheartedly agree that mixin composition is superior to both prototype and class-based inheritance. I'm not sure I entirely follow your point regarding `this', though. (TBH, I'd prefer not having a `this' keyword at all, because not being alpha-convertible, it doesn't really compose with

Re: What do we still need from a class-like abstraction (was: `this`: methods versus functions)

2011-11-10 Thread Jake Verbaten
The only value prototype inheritance gives is the fact you can change the prototype and changes are reflected. If you do not want that feature then use mixins. On Thu, Nov 10, 2011 at 4:56 PM, Andreas Rossberg rossb...@google.comwrote: I wholeheartedly agree that mixin composition is superior

Re: What do we still need from a class-like abstraction (was: `this`: methods versus functions)

2011-11-10 Thread Brendan Eich
On Nov 10, 2011, at 7:59 AM, Mark S. Miller wrote: My previous proposal for class-like sugar for traits composition was not popular. Whereas, in the absence of problem #5, I suspect the traitsjs library would be. As previously observed on this list, traitsjs is more JavaScripty. Ideal

Re: What do we still need from a class-like abstraction (was: `this`: methods versus functions)

2011-11-10 Thread Brendan Eich
On Nov 10, 2011, at 2:07 PM, Brendan Eich wrote: On Nov 10, 2011, at 7:59 AM, Mark S. Miller wrote: My previous proposal for class-like sugar for traits composition was not popular. Whereas, in the absence of problem #5, I suspect the traitsjs library would be. As previously observed on

`this`: methods versus functions

2011-11-09 Thread Axel Rauschmayer
Or are there other plans to get it solved? I would still love to see that happen, it’s a remarkably subtle source of errors. Could functions adopt the block-lambda semantics of picking up the `this` of the surrounding scope when not invoked as methods? It seems like that could work in

Re: `this`: methods versus functions

2011-11-09 Thread Brendan Eich
On Nov 9, 2011, at 3:48 PM, Axel Rauschmayer wrote: Or are there other plans to get it solved? I would still love to see that happen, it’s a remarkably subtle source of errors. Could functions adopt the block-lambda semantics of picking up the `this` of the surrounding scope when not

Re: `this`: methods versus functions

2011-11-09 Thread Mark S. Miller
On Wed, Nov 9, 2011 at 4:00 PM, Brendan Eich bren...@mozilla.com wrote: On Nov 9, 2011, at 3:48 PM, Axel Rauschmayer wrote: We talked about lexical this for functions long ago (Jan. 2008? at Google anyway) and IIRC Mark found a subtler flaw. I think my original example was smaller and more

Re: `this`: methods versus functions

2011-11-09 Thread Axel Rauschmayer
Got it. I’m assuming that’s a performance issue? You could say that. If we inherit by default but it's a soft binding, then the inner function has to carry that reference with it, but in a way that can be overridden. We talked about lexical this for functions long ago (Jan. 2008? at

Re: `this`: methods versus functions

2011-11-09 Thread Brendan Eich
On Nov 9, 2011, at 4:15 PM, Mark S. Miller wrote: On Wed, Nov 9, 2011 at 4:00 PM, Brendan Eich bren...@mozilla.com wrote: On Nov 9, 2011, at 3:48 PM, Axel Rauschmayer wrote: We talked about lexical this for functions long ago (Jan. 2008? at Google anyway) and IIRC Mark found a subtler