oortcloud_domicile
oortcloud_domicile

Reputation: 850

how to check if a javascript object has an instance of a particular object

say i have an array x and a constructor

function Road(footpath,divider,length,lanes){}

and

x[1] = new Road(1,1,1,1);

now how do i determine that x[1] is an object of type Road?

Upvotes: 0

Views: 36

Answers (1)

Renato Gama
Renato Gama

Reputation: 16519

Simple like this

if(x[1] instanceof Road) {
    //Hey, you have a road!
}

Upvotes: 4

Related Questions