substitutes for arguments and arguments.callee in ECMAScript 5

Felipe Gasper felipe at felipegasper.com
Wed Jan 5 12:06:27 PST 2011


On 1/5/11 1:43 PM, Allen Wirfs-Brock wrote:
> On Jan 5, 2011, at 11:30 AM, Felipe Gasper wrote:
>
>> Am I to understand now that ECMASCript 5 will now have me type in:
>>
>> ----
>> var func;
>> a_dialog.hideEvent.subscribe( func = function() {
>> this.hideEvent.unsubscribe( func );
>> console.log("This will only happen once.");
>> } );
>
> No, what you should type is:
>
> a_dialog.hideEvent.subscribe( function func() {
> this.hideEvent.unsubscribe( func );
> console.log("This will only happen once.");
> } );

Ah - thanks.

That would seem to work in most cases, but the subtle differences between

var foo = function() { ... }

and

function foo() { ... }

...make me a little uncertain. Crockford says in “The Good Parts” that 
“it turns out that *most* browsers allow function statements in if 
statements” (p113, emphasis added), but he doesn’t elaborate on which 
browsers that does/doesn’t mean. And there are differences of scope 
between the two declarations of the function that seem to invite subtle 
bugs.

-F


More information about the es-discuss mailing list