Subj : Re: Strange ".constructor" behaviour -- I don't understand something, To : netscape.public.mozilla.jseng From : Martin Honnen Date : Tue Oct 04 2005 06:27 pm Lev Serebryakov wrote: >>You are not adding some methods you are creating a new prototype object >>that way. > > Yes. But not new constructor! The object itself has no own property named 'constructor', it is a property inherited from the prototype chain. > So, default prototype object contains > "prototype" property magically added to it, not to object when it is > created? The whole stuff is dynamic, try this example to see function Class() {} var c1 = new Class(); var result = []; result.push('c1.hasOwnProperty("constructor"): ' + c1.hasOwnProperty("constructor")); result.push('c1.constructor.name: ' + c1.constructor.name); result.push('c1.__proto__.hasOwnProperty("constructor"): ' + c1.__proto__.hasOwnProperty("constructor")); // now change prototype Class.prototype = { method: function() {} }; var c2 = new Class(); result.push('c2.constructor.name: ' + c2.constructor.name); result.join('\r\n') In Spidermonkey the prototype chain is exposed through the __proto__ property and you can see that the object created with new Class() does not have its own property named 'constructor' but only the one sitting in its prototype chain. -- Martin Honnen http://JavaScript.FAQTs.com/ .