Shorthand Function declaration
# Tab Atkins Jr. (11 years ago)
my_list.map(<val>{return val<0?-val:val;});//return absolut-ified array content
Are you aware of the existing arrow functions? Using current ES6, your example would be written as:
my_list.map(val=>val<0?-val:val);
On Tue, Feb 11, 2014 at 12:33 PM, biscotte a la crevette <biscottealacrevette at gmail.com> wrote: > I would like to suggest an alternative function declaration syntax rule : > http://pastebin.mozilla.org/4258633 > > That will lead to a way shorter function declaration (like Array [...] > and Object {...} does ) : > > long story short : <...> will be equivalent to function(...) > > Which mean : > > var print = <name,age>{ //eq. to var print = function(name,age){... > console.log("my name is " + name + " " + age + "y old.\n"); > } > > Human = <name,age=0>{ > this.age=age; > this.name=age; > this.toString=<>{ > return ... > }; > } > > And so, will work with anonymous function declaration (which was my main goal). > > my_list.map(<val>{return val<0?-val:val;});//return absolut-ified array content Are you aware of the existing arrow functions? Using current ES6, your example would be written as: my_list.map(val=>val<0?-val:val); ~TJ
# Till Schneidereit (11 years ago)
Also, there are short method declarations:
var obj = {
foo(bar, baz) {
// stuffs
}
}
On Wed, Feb 12, 2014 at 9:39 AM, Tab Atkins Jr. <jackalmage at gmail.com>wrote: > On Tue, Feb 11, 2014 at 12:33 PM, biscotte a la crevette > <biscottealacrevette at gmail.com> wrote: > > I would like to suggest an alternative function declaration syntax rule : > > http://pastebin.mozilla.org/4258633 > > > > That will lead to a way shorter function declaration (like Array [...] > > and Object {...} does ) : > > > > long story short : <...> will be equivalent to function(...) > > > > Which mean : > > > > var print = <name,age>{ //eq. to var print = function(name,age){... > > console.log("my name is " + name + " " + age + "y old.\n"); > > } > > > > Human = <name,age=0>{ > > this.age=age; > > this.name=age; > > this.toString=<>{ > > return ... > > }; > > } > > > > And so, will work with anonymous function declaration (which was my main > goal). > > > > my_list.map(<val>{return val<0?-val:val;});//return absolut-ified array > content > > Are you aware of the existing arrow functions? Using current ES6, > your example would be written as: > > my_list.map(val=>val<0?-val:val); > Also, there are short method declarations: var obj = { foo(bar, baz) { // stuffs } } -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140212/a5df7d63/attachment.html>
# Jeremy Martin (11 years ago)
Seems like this would lead to confusing operator precedence rules as well. For example:
1<<foo>{}
... is perfectly valid JavaScript today (syntactically, anyway...), and is equivalent to:
(1 << foo) > {}
... but I would assume that with the new syntax in place it would really be interpreted as:
1 < function(foo) {}
... which is also valid JavaScript. Not that either of those examples
should ever occur in the real world, but in general I think they indicate
that <
and >
might be better left alone.
Seems like this would lead to confusing operator precedence rules as well. For example: 1<<foo>{} ... is perfectly valid JavaScript today (syntactically, anyway...), and is equivalent to: (1 << foo) > {} ... but I would assume that with the new syntax in place it would really be interpreted as: 1 < function(foo) {} ... which is also valid JavaScript. Not that either of those examples should ever occur in the real world, but in general I think they indicate that `<` and `>` might be better left alone. On Tue, Feb 11, 2014 at 3:53 PM, Till Schneidereit < till at tillschneidereit.net> wrote: > On Wed, Feb 12, 2014 at 9:39 AM, Tab Atkins Jr. <jackalmage at gmail.com>wrote: > >> On Tue, Feb 11, 2014 at 12:33 PM, biscotte a la crevette >> <biscottealacrevette at gmail.com> wrote: >> > I would like to suggest an alternative function declaration syntax rule >> : >> > http://pastebin.mozilla.org/4258633 >> > >> > That will lead to a way shorter function declaration (like Array [...] >> > and Object {...} does ) : >> > >> > long story short : <...> will be equivalent to function(...) >> > >> > Which mean : >> > >> > var print = <name,age>{ //eq. to var print = function(name,age){... >> > console.log("my name is " + name + " " + age + "y old.\n"); >> > } >> > >> > Human = <name,age=0>{ >> > this.age=age; >> > this.name=age; >> > this.toString=<>{ >> > return ... >> > }; >> > } >> > >> > And so, will work with anonymous function declaration (which was my >> main goal). >> > >> > my_list.map(<val>{return val<0?-val:val;});//return absolut-ified array >> content >> >> Are you aware of the existing arrow functions? Using current ES6, >> your example would be written as: >> >> my_list.map(val=>val<0?-val:val); >> > > Also, there are short method declarations: > > var obj = { > foo(bar, baz) { > // stuffs > } > } > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -- Jeremy Martin 661.312.3853 http://devsmash.com @jmar777 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140211/8858baaf/attachment.html>
# Jeremy Martin (11 years ago)
Forgot to mention, expression-only function bodies would be problematic as well.
1<foo>bar;
Is that a syntax error?
1 function(foo) { return bar; }
...or does it get interpreted as it would today?
Forgot to mention, expression-only function bodies would be problematic as well. 1<foo>bar; Is that a syntax error? 1 function(foo) { return bar; } ...or does it get interpreted as it would today? On Tue, Feb 11, 2014 at 4:10 PM, Jeremy Martin <jmar777 at gmail.com> wrote: > Seems like this would lead to confusing operator precedence rules as well. > For example: > > 1<<foo>{} > > ... is perfectly valid JavaScript today (syntactically, anyway...), and is > equivalent to: > > (1 << foo) > {} > > ... but I would assume that with the new syntax in place it would really > be interpreted as: > > 1 < function(foo) {} > > ... which is also valid JavaScript. Not that either of those examples > should ever occur in the real world, but in general I think they indicate > that `<` and `>` might be better left alone. > > > > On Tue, Feb 11, 2014 at 3:53 PM, Till Schneidereit < > till at tillschneidereit.net> wrote: > >> On Wed, Feb 12, 2014 at 9:39 AM, Tab Atkins Jr. <jackalmage at gmail.com>wrote: >> >>> On Tue, Feb 11, 2014 at 12:33 PM, biscotte a la crevette >>> <biscottealacrevette at gmail.com> wrote: >>> > I would like to suggest an alternative function declaration syntax >>> rule : >>> > http://pastebin.mozilla.org/4258633 >>> > >>> > That will lead to a way shorter function declaration (like Array [...] >>> > and Object {...} does ) : >>> > >>> > long story short : <...> will be equivalent to function(...) >>> > >>> > Which mean : >>> > >>> > var print = <name,age>{ //eq. to var print = function(name,age){... >>> > console.log("my name is " + name + " " + age + "y old.\n"); >>> > } >>> > >>> > Human = <name,age=0>{ >>> > this.age=age; >>> > this.name=age; >>> > this.toString=<>{ >>> > return ... >>> > }; >>> > } >>> > >>> > And so, will work with anonymous function declaration (which was my >>> main goal). >>> > >>> > my_list.map(<val>{return val<0?-val:val;});//return absolut-ified >>> array content >>> >>> Are you aware of the existing arrow functions? Using current ES6, >>> your example would be written as: >>> >>> my_list.map(val=>val<0?-val:val); >>> >> >> Also, there are short method declarations: >> >> var obj = { >> foo(bar, baz) { >> // stuffs >> } >> } >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > > > -- > Jeremy Martin > 661.312.3853 > http://devsmash.com > @jmar777 > -- Jeremy Martin 661.312.3853 http://devsmash.com @jmar777 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140211/b208eb6b/attachment-0001.html>
I would like to suggest an alternative function declaration syntax rule : pastebin.mozilla.org/4258633
That will lead to a way shorter function declaration (like Array [...] and Object {...} does ) :
long story short : <...> will be equivalent to function(...)
Which mean :
var print = <name,age>{ //eq. to var print = function(name,age){... console.log("my name is " + name + " " + age + "y old.\n"); } Human = <name,age=0>{ this.age=age; this.name=age; this.toString=<>{ return ... }; }
And so, will work with anonymous function declaration (which was my main goal).
I may could be even shorter if expression-only function result were implicitly returned and it statements treated like "while" and "if" are (optional braces on single statement) :
var list=[{name:"Johnny",age:36},{name:"Mary",age:35}]; list.map(<e>e.name;); //equivalent to : list.map(function(e){return e.name;});
I've implemented and tested this new rule.
Do you think it could be submitted to the next ES draft ?