I need to find a way to create a JavaScript object with null prototype.
I'm not allowed to use the Object.create function.
I tried instantiating a constructor like new Constructor(), but the returned object always has a non-null prototype, even if Constructor.prototype === null.
Such an object already exists, it's Object.prototype, so your code is as simple as
x = Object.prototype
but you cannot create a new object like this, because new always sets the proto to an object:
If Type(proto) is not Object, set the [[Prototype]] internal property of obj to the standard built-in Object prototype object as described in 15.2.4. @ http://ecma-international.org/ecma-262/5.1/#sec-13.2.2
You can manipulate __proto__ directly
a = {}
a.__proto__ = null
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With