On Constructors

Some say you should never use the new operator in your JavaScript. I use it when I want to create a family of objects all varying in their data properties’ values. That is just what OOP languages do. We think the huge success of C++, Java, and other OOP languages tells you that this paradigm commonly matches at least some of the realities our programs model.

Unfortunately, the new operator’s implementation in JavaScript could hardly be more confusing. Knowing exactly how this operator functions may help you shine in interviews but it will not help you write code.

If you skim or entirely skip this chapter I won’t be disappointed. ...

Get JavaScript Object Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.