Creating Objects With A Null Prototype In Node.js

added by JavaScript Kicks
3/10/2015 5:32:00 PM


A while back, when I was reading the Principles Of Object-Oriented JavaScript by Nicholas Zakas, I came across a tip about using Object.create() to create objects with a null prototype. Such an object wouldn't inherit from Object.prototype and would, therefore, have no keys in it. Zakas suggested that this could be used to safely create a "cache" object. I really liked this idea; but, according to the MDN (Mozilla Developer Network), Object.create() wasn't supported until IE9, which made it tough(er) to use in the browser. But, in Node.js - on the server - it can be used with full support.