If you assign to members or add members to the prototype, you will still have 
an existing f.constructor.

In the code below, you'll now also have 
Foo.prototype.function_name.prototype.constructor as well.

On Jun 4, 2012, at 9:08 PM, dhruvbird wrote:

> ah! Thanks! I didn't realize that. So the correct way to do it would
> be to say:
> 
> Foo.prototype.function_name = function foo() { /* blah */ };
> 
> eh?
> 
> Regards,
> -Dhruv.
> 
> On Jun 3, 5:59 am, Michael Schwartz <[email protected]> wrote:
>> constructor is part of the prototype.  You wiped it out by assigning the 
>> prototype to {}, which has a constructor of object.
>> 
>> On Jun 3, 2012, at 12:00 AM, dhruvbird wrote:
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>> Hello,
>> 
>>> I see different output for these 2 snippets of code. The only
>>> difference between them is that a prototype is defined on one of them,
>>> but not on the other.
>> 
>>> // Snippet-1:
>>> function Foo() { }
>>> var f = new Foo;
>>> console.log(f.constructor.name); // Prints "Foo"
>> 
>>> // Snippet-2:
>>> function Foo() { }
>>> Foo.prototype = { };
>>> var f = new Foo;
>>> console.log(f.constructor.name); // Prints "Object"
>> 
>>> Any idea why the behaviour changes by just adding a prototype?
>> 
>>> Regards,
>>> -Dhruv.
>> 
>>> --
>>> v8-users mailing list
>>> [email protected]
>>> http://groups.google.com/group/v8-users
> 
> -- 
> v8-users mailing list
> [email protected]
> http://groups.google.com/group/v8-users

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to