javascript - Defining Classes in JS (ES5 vs Prototype) -
i looking @ common ways of defining classes (constructor pattern in book addy osmani).
2 main ways see:
simple prototypes:
function person(name) { this.name = name; } person.prototype.getname = function() { return this.name; }
es5
object.create
,object.defineproperties
i wondering, why might consider es5 way appears alot more complicated? there advantages? maybe main advantage having read-only properties typed language?
object.defineproperties
needed if want properties have particular attributes, e.g. non-enumerable, read-only, or getters or setter functions.
there's no need use normal classes , methods, "simple prototype" method describe adequate.
Comments
Post a Comment