> OK, but that's odd... somewhere internally there must be a reference
> from each object to its prototype. We can see this in the way
> properties are looked up. But, if we don't store it ourselves, there is
> really no way to find out what that prototype is?
Not in plain standard JavaScript (ECMAScript 3rd edition).
Many implementations, including V8, gives access to the prototype link
as the pseudo-property "__proto__".
> (Basically I'm trying to construct an "is-a" test to see whether one
> object derives from another via the prototype chain.)
You can use the Object.prototype.isPrototypeOf method:
potentialPrototype.isPrototypeOf(object)
or, if you want something more complex, you can use the instanceof
operator with a specially crafted function object:
function derivesFrom(object, potentialPrototype) {
var dummy = function() {};
dummy.prototype = potentialPrototype;
return object instanceof dummy;
}
Best of luck
/L
--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---