On Mar 4, 2009, at 3:52 PM, Brendan Eich wrote:

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.

The authors of Objective-J and the Capuccino framework have asked us to either make Function.name mutable or else provide a way to construct a function with a provided name. Since they use language translation, they would like the debugger and other tools to reflect the original declared names such as "[MyClassName methodWithParam:andStuff:]", in other words Objective-C looking methods. I don't know if language translation is the world's greatest thing but it seemed like a valid use case to me when they suggested it.

Regards,
Maciej

_______________________________________________
Es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to