name property for built-in functions??

Brendan Eich brendan at mozilla.com
Wed Mar 4 15:52:06 PST 2009


On Mar 4, 2009, at 1:38 PM, Jeff Watkins wrote:

> Can I suggest that allowing writing to name may be helpful when  
> creating transparent wrapper functions?
>
> We do a lot of this:
>
> function wrapWithChangeNotification(key, fn)
> {
> 	return function()
> 	{
> 		this.willChangeValueForKey(key);
> 		var result= fn.apply(this, arguments);
> 		this.didChangeValueForKey(key);
> 		return result;
> 	}
> }
>
> I'd love it if I could set the name on the new function to match the  
> original function.

Why? I mean, do you expect to see that assigned name in a future  
toString() result?

The integrity of name reflecting the declared identifier seems worth  
something. Is this a case where anonymous function objects should have  
no name property at all, allowing you to create one (even with high  
integrity, using ES3.1's Object.defineProperty), while named function  
expressions and function definitions should induce a function object  
with a readonly name property?

We could certainly change Mozilla's implementations to allow name to  
be written but there's a tension here between integrity and  
mutability. It seems worth a bit more discussion.

/be



More information about the Es-discuss mailing list