4 ms·
Part of the problem with JavaScript is that prototypes are an inherent part of the language, but wrapped up behind syntactic sugar that hides them away on the f
by iMark 14y ago
Part of the problem with JavaScript is that prototypes are an inherent part of the language, but wrapped up behind syntactic sugar that hides them away on the fringes of the language.
If you've created an object in JavaScript, you've used prototypes, just indirectly.
If you want to use inheritance in Javascript prototypes are where it's at.
The ObjectName.prototype.fn = function() {} pattern is also a more memory efficient way of defining object methods than doing function ObjectName() {this.fn = function() {}}, as the method is only defined once in the former case, but is defined every single time a object is created in the latter case.
Basically for the most part you don't have to use prototypes directly, but more you know about them the better.