name property for built-in functions??

Garrett Smith dhtmlkitchen at
Wed Mar 11 10:24:27 PDT 2009

On Wed, Mar 11, 2009 at 3:31 AM, David-Sarah Hopwood
<david.hopwood at> wrote:
> Garrett Smith wrote:


>> Maciej' Function.create proposal:-
>> Function.create("[Foo bar]", "param1", "param2", "code(); goes(); here();");


>> Possible alternative:-
>>   Function.create( name, fun[, context] );
> I don't see the problem here that would require overriding the context.

No problem there.

The problem was with the other (Maciej') Function.create.

Function.create param |code|, as a string would be used to build a
Function. That function would have to have global scope. To use the
calling context's scope (as eval does) would be a security issue.

To *not* use the calling context's scope would not allow for wrapping
functions (Jeff Watkins' use case).

> The scope used by fun would be its original lexical scope. In the example
> above:
>  EventPublisher.fireEvent = function(publisher) {
>    return Function.create(publisher.eventName + "Handler", function(ev) {
>      // code here
>      // can refer to 'publisher', etc. if needed
>    });
>  };
> All the hypothetical Function.create does is to create a new function that
> behaves the same as its fun argument, but with a different name. The
> .name property of all function objects would be non-[[Writable]] and
> non-[[Configurable]].
> Whether this is actually needed, I'm not sure, but it has all of the
> functional and security properties I've seen stated as desirable so far
> in this thread.

I agree on both points. It is secure this way, but I am not sure if it
is needed.

If used for debugging, what would the debugger step into for:-

var f2 = Function.create("f2", fun)(0);

function fun(i) {
  if(i === 0) throw Error("zero");



More information about the Es-discuss mailing list