If I write this
var o = Object.create(null)
alert(o instanceof Object) // this is false
How come this ends up being true
function o() {
}
o.prototype = null
alert(new o() instanceof Object) // this is true
Shouldn’t manually setting the prototype to null cause it to inherit from nothing as Object.create does. Thanks in advance 🙂
Briefly, if a constructor’s prototype isn’t an Object, then instances are given Object.prototype as their [[prototype]].
The detail is in ECMA-262, §13.2.2 [[Construct]]:
Noting that in items 6 and 7,
nullis Type null (ECMA-262 §8.2), it is not the same astypeof null, which is object.