Tag Archives: patterns

Patterns for enforcing “new”

Recently I was looking around for a book on JavaScript Patterns. I decided to give the JavaScript Patterns by Stoyan Stefanov a try. If you have been looking for a book on Javascript Patterns, I highly recommend this book.

In the 3rd chapter, Literals and Constructors, I noticed this section on “Patterns for enforcing new” with the following entry:

When your constructor has something like this.member and you invoke the constructor without new, you’re actually creating a new property of the global object called member and accessible through window.member or simply member. This behavior is highly undesirable, because you know you should always strive for keeping the global namespace clean.

Continue reading