arguments.callee in Harmony

Luke Smith lsmith at lucassmith.name
Thu Sep 24 18:05:23 PDT 2009


The use of named function expressions is not correctly implemented by  
at least IE 6-8.

The basic use case works fine (e.g.)
var foo = function callee() {
     // do something
     setTimeout(callee, 10);
};

But declared as
(function callee() {
     // do something
     setTimeout(callee, 10);
})();

the name callee leaks to the enclosing scope.

Also, the callee function inside the function body is not the same  
function.  foo !== callee in IE.

So if you use the function as a namespace, callee.someProperty = "foo"  
is not exposed on foo.someProperty.

See http://lucassmith.name/pub/named_func_exp.html

Luke

On Sep 24, 2009, at 3:59 PM, Oliver Hunt wrote:

>
> On Sep 24, 2009, at 3:55 PM, Charles Jolley wrote:
>
>>> Given your example, a named function expression would do the job  
>>> trivially:
>>>
>>> ClassB = ClassA.extend({
>>>
>>>   foo: function foo() {
>>>     foo.base.apply(this, arguments); // calls super!
>>>     // other code
>>>   }
>>>
>>> });
>>
>> This works but, as I said, this approach has a couple of drawbacks:
>>
>> 1. The function has to be named twice (foo: function foo()).  This  
>> makes the code harder to read (especially with long names) and its  
>> not very developer-friendly since its pointless cruft.
>>
>> 2. This is also fragile.  If you forget the second name, the code  
>> would still parse but it will be seriously broken.  Additionally,  
>> if you decided to rename the function you would also have to edit  
>> the code on the inside.  Hurts the "copy and paste" aspect of it.
>>
>> In general I think this particular approach is not developer  
>> friendly enough.
> The function expression name is fairly irrelevant, so you could have  
> a standard style guideline
> foo : function callee() {
>     callee.base.apply ...
> }
>
> --Oliver
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20090924/eaf95c2f/attachment.html>


More information about the es-discuss mailing list