I want to check if my javascript object is of a certain type.
I have an object (I cannot edit this object.) and I have made instances of that object. Now I want to loop through all the objects that are available at any given point and figure out which ones are the instances that I am looking for.
Example:
var myObject = function() { };
var obj_person = new myObject();
Now if I write
typeof obj_person
It gives me object
which is not useful. I cannot use instanceof
as it does not work in IE8.
Is there anyway to check if obj_person is an instance of myObject?
Thanks.
EDITED***
Here is the code
var arr_instances = [];
for(var v in window)
{
var obj_required;
if(typeof window[v] == 'object')
{
obj_required = window[v];
if(obj_required.imgSrc)
{
arr_instances.push(obj_required);
}
}
}
Then I can iterate withing arr_instance and do whatever I want to do.
for(var i=0; i<arr_instances.len; i++)
{
if(arr_instances[i].imgSrc == 'requiredImg.jpg')
{
arr_instances[i].imgSrc = 'newImg.jpg';
}
}