On Jan 5, 2011, at 12:06 PM, Felipe Gasper wrote:
> 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.
Allen's revision of your example is not using any extension to ES3. It's using
a named function expression.
Functions in blocks are an extension, implemented variously.
Unfortunately, even named function expressions have a notorious bug up through
IE8 (IIRC) where the name is bound in the variable object.
/be
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss