On 9/23/07, Brendan Eich <[EMAIL PROTECTED]> wrote:
> On Sep 23, 2007, at 12:22 PM, Garrett Smith wrote:
>
> >>> in no case is the value of (new function(){}).constructor Function.
> >>
> > It shouldn't be, but it is in OSX Ref Impl. (I did not build this).
> >
> > js> (new function(){}).constructor
> > [function Function]
>
> No, that's just http://bugs.ecmascript.org/ticket/64 -- proof:
>
>  >> (new function(){}).constructor
> [function Function]
>  >> (new function(){}).constructor === Function
> false
>  >> f = function(){}
> [function Function]
>  >> (new f).constructor === f
> true
>  >>
>
Ah, OK.

js> Function().toSource()
function(){}

Works.

I usually like modifying toString anyway.

F = function(){};
F.prototype = {
    toString : function() {
        return "Fork!";
    }
};
f = new F;
f.toString()
//f.constructor


> With Function.prototype.toString buggy, you need to test identity of
> function objects.
>
Buggy or not, since functions could have different [[Scope]], testing
toString makes no sense.

Testing toSource is useful for seeing if it's a native function (eval,
or RegExp test), but Function.prototype.toSource() isn't provided in
the spec and isn't supported in JScript.

Garrett

> /be
>


-- 
Programming is a collaborative art.
_______________________________________________
Es4-discuss mailing list
Es4-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es4-discuss

Reply via email to