15.2.4.6 Object.prototype.isPrototypeOf(V)

2010-07-04

boolean Object.prototype.isPrototypeOf(V:object|mixed)

Returns true if O.[[Prototype]] == V.

Code: (Meta Ecma)
Object.prototype.isPrototypeOf = function(V){
if (!IsObject(V)) return false; // todo: define IsObject?
var O = ToObject(this);
while (true) {
var V = V.[[Prototype]];
if (V === null) return false;
if (O === V) return true;
}
}

Note that V is checked to be an object first to preserve behaviour of older specifications, in case this is undefined or null (then ToObject throws an error).