I have done a fair amount of programming in JavaScript/JQuery.
But I never used “prototype”. In fact, I have no clue what it means.
Do you have a practical example when it is useful?
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.
Simplest example:
Now you can create as many instances of
Fooas you want and callbar():Even though both object have
bar()method which is exactly the same in both cases, these are distinct methods. In fact, each newFooobject will have a new copy of this method.On the other hand:
has the same end result but the function is stored only once in object
prototyperather than in an object itself. This may be a deal breaker if you create tons ofFooinstances and want to save some memory.