isPrototypeOf()  Object  instance method getterS2C Home  « Globals « Object « isPrototypeOf()

Description

Returns a boolean indicating whether the object exists in another objects hierarchy.

Syntax

Signature Description
prototype.isPrototypeOf(object)Returns a boolean indicating whether the object exists in another objects hierarchy.

Parameters

Parameter Description
prototypeThe object prototype to be checked against Object.
objectThe object chain to be checked in for the prototype.

Examples

The code below checks objects against a prototype chain.


// Create Prototypes.
function AFunc(aProp) {  
  this.aProp=aProp;  
}  
function BFunc(bProp) {  
  this.bProp=bProp;  
}  
BFunc.prototype = new AFunc();

function CFunc(cProp) {  
  this.cProp=cProp;  
} 
CFunc.prototype = new AFunc(); 

// Create an object and check against prototype chains.
var cObj = new CFunc();

if (AFunc.prototype.isPrototypeOf(cObj)) {
  alert('AFunc is prototype of CFunc')
} else {
  alert('AFunc is NOT a prototype of CFunc')
}

if (BFunc.prototype.isPrototypeOf(cObj)) {
  alert('BFunc is prototype of CFunc')
} else {
  alert('BFunc is NOT a prototype of CFunc')
} 

Press the button below to action the above code:


Related Tutorials

JavaScript Basic Tutorials - Lesson 7 - Objects

go to home page Homepage go to top of page Top