An Object That’s Not

In JavaScript, objects just love their prototypes. And why wouldn’t they? Whenever they are in need of a property, hey, they can always check up the inheritance chain and try to find it. It’s good to know someone always has your back!

But, what if no one had your back?

$ js
js> var obj = {};
js> obj.toString();
[object Object]
js> obj.__proto__ = null;
null
js> obj.toString();
typein:4: TypeError: obj.toString is not a function
js>

hwaaa!

js> obj+obj
typein:5: TypeError: can't convert obj to primitive type
js> typeof obj.__proto__
undefined
js>

Poor obj has no prototype to inherit from anymore - we set it to null. It knows nothing of the built in wonders inherited from Object.prototype. No toString, no hasOwnProprty, no nothing.

There’s even a way to wipe out Object.prototype for everyone (I’ll leave this as an exercise for the reader.)

Direct access to the inherited prototype can sure do some wacky things, indeed. I’ll post on the more useful functionalities I’ve found in a bit.