13.2.2 [[Construct]], constructor, and [[Class]] (was __proto__)
Garrett Smith
dhtmlkitchen at gmail.com
Sun Sep 23 15:48:03 PDT 2007
On 9/23/07, Brendan Eich <brendan at mozilla.org> 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.
More information about the Es4-discuss
mailing list