3 ms·
A class is a blueprint you go to for constructing new objects. A prototype is an object you create once that is copied to a variable when the constructor is cal
by turndown 5y ago
A class is a blueprint you go to for constructing new objects. A prototype is an object you create once that is copied to a variable when the constructor is called. That is how I understand it, but maybe someone else can explain further.
- k__ 5y agoYou can think of a prototype as a fallback for your object. If something doesn't exist on your object, JS will check if it has a prototype and look there transparently. Now, if you got a prototype chain, JS will move through it in the hope to find what you wanted to access on the original object. try to access obj.a not there? try to access obj.prototype.a not there? try to access obj.prototype.prototype.a etc. The nice thing is "this" will usually (if you call a function as method and not pass a reference of it around for callbacks and such) refer to the object and not the prototype. Also, writes happen on the object.