Entry
How do I call a function delayed AND pass an object along?
Feb 2nd, 2002 16:53
ralf bokelberg, Techek,
// you can use a anonymous function to achieve this.
// on the assignment of the function the actual scope is copied
function testFunc(parameterObject){
alert("testFunc " + typeof(parameterObject) + " " +
parameterObject.name);
}
pObj = new Object();
pObj.name="willi";
setTimeout(function(){testFunc(pObj)}, 1000);
// this even works with local variables
// the following example shows that myArray
// lives on, even if initVars is finished
function initVars(){
var myArray = [1,2,3,4];
myfunc = function(){alert(myArray)};
}
initVars();
myfunc();