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

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -