Re: Syntactic sugar for using a function as if it were a method of its first argument

2014-05-27 Thread Jasper St. Pierre
It's fairly incomprehensible to me, and doesn't really have any advantages over writing it out the long way: Object.getOwnPropertyDescriptor(window.HTMLFormElement.prototype, 'elements').get window.HTMLFormElement.prototype{Object.getOwnPropertyDescriptor}('elements').get They're both the

Re: Syntactic sugar for using a function as if it were a method of its first argument

2014-05-27 Thread Claude Pache
Le 27 mai 2014 à 17:04, Jasper St. Pierre jstpie...@mecheye.net a écrit : (...) Namely, the whole ('elements') looks like a method call containing one argument, rather than having a secret hidden argument as its first. Yes, it was exactly intended to appear as such, making

Re: Syntactic sugar for using a function as if it were a method of its first argument

2014-05-27 Thread C. Scott Ananian
I like the idea, but I agree that the .{ } syntax isn't quite right. For one thing, on my screen the () are visually very similar to {}, while [] are easily distinguished. The leading dot is also a bit odd. I'd be interested in seeing some more alternative syntaxes for this idea. --scott On

Re: Syntactic sugar for using a function as if it were a method of its first argument

2014-05-27 Thread Andrea Giammarchi
( already covered to receive stones ) ```javascript Object.defineProperty( Object.prototype, 'through', { enumerable: false, configurable: true, writable: true, value: function through(callback) { for (var a = [this], i = 1; i arguments.length; a[i] =

RE: Syntactic sugar for using a function as if it were a method of its first argument

2014-05-27 Thread Nathan Wall
I have a syntax proposal, but it goes along with a slightly different way of thinking of this. The proposed bind operator[1] can take a function which acts as a method and make a call to it with a specific receiver without the receiver needing to have the method defined as a property (basically

RE: Syntactic sugar for using a function as if it were a method of its first argument

2014-05-27 Thread Nathan Wall
(Sorry about the formatting in the last one. Trying again.) I have a syntax proposal, but it goes along with a slightly different way of thinking of this. The proposed bind operator[1] can take a function which acts as a method and make a call to it with a specific receiver without the

Re: Syntactic sugar for using a function as if it were a method of its first argument

2014-05-27 Thread Jasper St. Pierre
I'm not sure I like it. Given how other languages use the :: operator, I'd expect Foo::bar to do some sort of static property lookup for a name called bar on Foo, not bind the local variable Foo to the local variable bar. I think bar.bind(Foo) is more than enough. I am OK with your curryThis

Re: Syntactic sugar for using a function as if it were a method of its first argument

2014-05-27 Thread Andrea Giammarchi
Sorry Nathan but how is this different from extending Object prototype? you are basically polluting everywhere `::` operator, can't see any less conflictual scenario than just polluting the `.` one in terms of prototype On Tue, May 27, 2014 at 11:17 AM, Nathan Wall nathan.w...@live.com wrote:

Re: Syntactic sugar for using a function as if it were a method of its first argument

2014-05-27 Thread Brendan Eich
Jasper St. Pierre wrote: I'm not sure I like it. Given how other languages use the :: operator, I'd expect Foo::bar to do some sort of static property lookup for a name called bar on Foo, not bind the local variable Foo to the local variable bar. That's not what the proposed bind operator

Re: Syntactic sugar for using a function as if it were a method of its first argument

2014-05-27 Thread Jasper St. Pierre
From my reading of the email and strawman page, let f = obj::foo; is exactly equivalent to let f = foo.bind(obj); Am I wrong? How is the result subtly different? Really, with obj::foo, I would expect obj::foo to be the same as obj.foo.bind(obj);, not foo.bind(obj); And even then, I don't think

Re: Syntactic sugar for using a function as if it were a method of its first argument

2014-05-27 Thread Tab Atkins Jr.
On Tue, May 27, 2014 at 12:40 PM, Jasper St. Pierre jstpie...@mecheye.net wrote: From my reading of the email and strawman page, let f = obj::foo; is exactly equivalent to let f = foo.bind(obj); Am I wrong? How is the result subtly different? Brendan's saying that the return value of

Re: Syntactic sugar for using a function as if it were a method of its first argument

2014-05-27 Thread Claude Pache
This sounds good to me. Just a nit, you should define: Function.curryThis = function(f, base = undefined) { return function(...args) { return f.call(base, this, ...args); }; }; so that you can do, e.g., class ImprovedArray extends Array { /* _not_

Re: Syntactic sugar for using a function as if it were a method of its first argument

2014-05-27 Thread Claude Pache
Le 27 mai 2014 à 20:59, Andrea Giammarchi andrea.giammar...@gmail.com a écrit : Sorry Nathan but how is this different from extending Object prototype? you are basically polluting everywhere `::` operator, can't see any less conflictual scenario than just polluting the `.` one in terms of

Re: Syntactic sugar for using a function as if it were a method of its first argument

2014-05-27 Thread Andrea Giammarchi
I did indeed !!! Interesting, thanks for the clarification. On Tue, May 27, 2014 at 3:44 PM, Claude Pache claude.pa...@gmail.comwrote: Le 27 mai 2014 à 20:59, Andrea Giammarchi andrea.giammar...@gmail.com a écrit : Sorry Nathan but how is this different from extending Object prototype?