Wow, I just figured out the answer on my own. I was working on a different part of the same project and I was using the setTimeout(). I was trying to pass the string of the id property of my object. I kept getting an error and I found out that I was passing the object itself. So I figured out that if you have a string variable of a object name and pass that as a argument to a function using the setTimeout(), the argument will be that object.
Here is a basic sample of the code I came up with:
Code:
//global variable
var global_is_a_object;
//the object function
function myObject(id, arg2, arg3)
{
//properties
this.id = id;
this.something = arg2;
this.something_else = arg3;
//this is a check variable
this.is_obj = "yes";
//set global variable to false
global_is_a_object = false;
//create a variable for the id if this does not happen
//and the id does not match the variable name a undefined
//variable will be passed to the check function
window[id] = "";
//call function to start the check function
some_function(id);
}
//this function starts the check
function some_function(theID)
{
//when the setTimeout function is set up like this, the variable: theID
//is passed to the function as a variable named the value of the theID variable
var timmerID = setTimeout("isAObject(" + theID + ")", 1);
//so if the theID has a value of "myObj" then what we're doing here is
//calling the function like this: isAObject(myObj)
}
//the check function
function isAObject(obj)
{
//if obj has a type of an object
if(typeof(obj) == "object") {
//check the property
if(obj.is_obj == "yes") { global_is_a_object = true; }
else { global_is_a_object = false; }
} else { global_is_a_object = false; }
if(global_is_a_object) {
//we're good
alert("the id is the same");
} else {
//we're not good
alert("the id is not the same");
}
}
//set objects
var myNewObject = new myObject("myNewObject", "blah", "something");
var myNewObject2 = new myObject("myNewObject2", "blah", "something");
Bookmarks