Possible Duplicate:
How does JavaScript .prototype work?
What is the use of prototype property when properties can be added to object even without it?
var o = {};
o.x = 5;
o.y = test;
test = new function(){ alert("hello"); };
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Adding a method / property to a prototype is adding it to all objects with that prototype in their prototype chain.
Your code is adding a method/property to a single instance.
To make use of prototypes you need to create your objects using new. If you create an object via an object literal you aren’t specifying the prototype for the object, as far as I know you can’t set the prototype retrospectively.