Im new to Node js language In most of the Node js sample app all are using prototype.Then i came to know using prototype we can add the methods and properties into an object.Still i'm not clear about what is the use of prototype.Can anyone explain me.
Asked
Active
Viewed 3,578 times
1
-
1This may be helpful: https://developer.mozilla.org/en-US/docs/JavaScript/Introduction_to_Object-Oriented_JavaScript – Blender Apr 03 '13 at 09:15
-
3Prototyping is a characteristic of Javascript, the language `node.js` is based on. I suggest you to read some resource about Javascript and prototyping. For example [the 8th chapter of Eloquent Javascript](http://eloquentjavascript.net/chapter8.html). – Alberto De Caro Apr 03 '13 at 09:27
-
possible duplicate of [How does JavaScript .prototype work?](http://stackoverflow.com/questions/572897/how-does-javascript-prototype-work) or [Javascript when to use prototypes](http://stackoverflow.com/q/4736910/1048572) - there is nothing specific about Node.js! – Bergi Apr 03 '13 at 10:03
2 Answers
1
In short, prototype
is used to build the interface (and implementation) of your custom-build objects in JavaScript.
As said Blender in the comment, it's how you do real OOP in JavaScript.

Mathieu Amiot
- 1,204
- 8
- 16
1
Using a prototype will also mean that you can define a method in one place (low memory footprint). Not defining a method via a prototype means that the method is defined for each instance of said object (high memory footprint).

Sebastian Patten
- 7,157
- 4
- 45
- 51