CHAPTER 9

image

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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.