Subj : Re: Strange ".constructor" behaviour -- I don't understand something, To : netscape.public.mozilla.jseng From : Martin Honnen Date : Tue Oct 04 2005 04:10 pm Lev Serebryakov wrote: > function Class() {} > var c = Class(); > print(c.constructor); > > Yes, it outputs "function Class() {}". It is Ok. It is exactly what I > expect. The above snippet will give you an error alike 'c has no properties'. Maybe you want var c = new Class(); as the second line? > Add some methods to this class: > > function Class() {} > Class.prototype = { method: function() {} }; You are not adding some methods you are creating a new prototype object that way. If you want to add a method then do Class.protoype.methodName = function () {}; If you then do function Class() {} Class.prototype.methodName = function () {}; var c = new Class(); then c.constructor and c.methodName should be what you want. Nevertheless the constructor property can be misleading if you build prototype based inheritance hierarchies but that is a known issue, try function Class () {} Class.prototype.methodName = function () {}; function SubClass () {} SubClass.prototype = new Class(); SubClass.prototype.methodName1 = function () {}; var object = new SubClass(); print(object.constructor) and you will get Class. It is what the ECMAScript specification wants however so you will often see code that manually corrects the constructor property as needed. -- Martin Honnen http://JavaScript.FAQTs.com/ .