function hoisting like var
Lars Hansen
lhansen at adobe.com
Fri Jul 25 07:17:33 PDT 2008
> -----Original Message-----
> From: Igor Bukanov [mailto:igor at mir2.org]
> Sent: 25. juli 2008 14:36
> To: Lars Hansen
> Cc: waldemar at google.com; es3.x-discuss at mozilla.org; es4-
> discuss at mozilla.org; Ingvar von Schoultz
> Subject: Re: function hoisting like var
>
> One way to get that extension comes from an observation that ES4
> allows to drop the braces around function body and the return keyword
> if the body is the single return exp. If ES3.1 would support it, then
> to simulate an effect of let expression like
>
> let (a = arg1, b = arg2) expression
>
> one could write
>
> (function(a, b) expression)(arg1, arg2)
>
> or
>
> (function(a, b) a = arg1, b = arg2, expression)()
>
> If, in addition to this shortcut, ES4 would allow to drop an empty
> argument list from a function with a requirement that function { }
> always means an expression and ES3.1 would also support that, then in
> place of a block with let variables one can write:
>
> function {
>
> }();
Even neater, using default argument values the syntax is actually
(function (a=arg1, b=arg2) expression)()
at which point 'let' is a trivial transformation.
--lars
More information about the Es4-discuss
mailing list