CHAPTER 6

image

More Ex Nihilo Objects

The more you write JavaScript, the more indispensable ex nihilo objects become. It seems that almost every senior JavaScript coder (senior by years of experience in JavaScript, not in life) uses ex nihilo objects as namespaces, which we’ll look at first. I claim a bit more originality for the idea of an ex nihilo class, our second example.

The Ex Nihilo Namespace Object

One of the most serious deficiencies of JavaScript is its lack of any namespace capability. It would be nice if my_code.js did not collide with your_code.js, but that requires some work on our part. The common solution is to create a namespace object ...

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.