arrow syntax unnecessary and the idea that "function" is too long
François REMY
fremycompany_pub at yahoo.fr
Mon May 9 02:19:50 PDT 2011
(...)
Let's ignore popularity level for the moment, no other proposal has analog of `=>` which is a solution for a real problem:
var self = this;
function callback() {
self....
}
Sorry, alternatives were evocated. If you had read my last mail (I know it was a pretty long one so I don’t blame you), you could have noticed that I proposed to use the @-syntax to perform just that. The idea would be that all lambdas would have a “bound” this (which would be the biggest distinctive between them and functions).
The syntax would be the following :
“@” + ( “(“ + <argument-list> + “)” )? + ( <expression> | <block> )
And it would allow to solve the “this” problem easily :
element.onclick = @this.removeFromParent();
setTimeout((@alert(this)), 10);
alongside with the other common lambda usage :
firstChilds = elements.map(@a.firstChild);
array.reduce(@(a,b) { return (a-b)*(a+b); });
In case you need to pass a function that has not a bound this, you should continue to use the “function” keyword as usual :
var anObjectHasOwnValueOf = Function.prototype.bind.call(function() {
return this.hasOwnProperty(“valueOf”);
}, anObject);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110509/c2b18770/attachment.html>
More information about the es-discuss
mailing list