eTianbun Posted October 14, 2011 Share Posted October 14, 2011 Why do i get undefined with this: function a(){}a.name="value";b=new a();alert(b.name)//prints:undefined. Link to comment Share on other sites More sharing options...
ShadowMage Posted October 14, 2011 Share Posted October 14, 2011 You are adding a property to the a object, not it's prototype. You could do: function a() { this.name='value';} or a.prototype.name='value'; If you want properties and methods to be part of every instance of an object, you need to add them to the prototype. Otherwise you will just create the property/method on the single instance of the object. Link to comment Share on other sites More sharing options...
eTianbun Posted October 14, 2011 Author Share Posted October 14, 2011 Thanks alot for the info! :-) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.