js

Creating Objects on JS

There are few interesting ways to create Objects on JS

Creating Objects on JS

Constructor function (classical inheritance pattern)

Literal notation (prototypal inheritance pattern)

Object-Based (ES5)

DEFINING Methods and Properties:

Constructor Way

Literal Way

Object-based (ES5)

Using them

Constructor Way

Literal Way

Object-based (ES5)

Final results:

Constructor Way

Literal Way

Object-based (ES5)

Final notes

Because of simplicity ES5 Object-Based sounds a good option, , we are not using new operator because we are using objects and not functions. Also it is well supported by legacy devices and browsers, or we can get the polyfill

Leave a Reply

Your email address will not be published. Required fields are marked *

* Copy This Password *

* Type Or Paste Password Here *