first is 'setTimeout'
second, do not pass the string. The actual solution depends on the rest of the code. The most reliable way would be to capture the scope:
var obj_array = something; function trap(obj) { function exec() { foo(obj); } return exec; } setTimeout(trap(obj_array), 1000);
Trap
returns a function in which your array falls into scope. This is a general function, but to be specific to your problem, it can be simplified:
var obj_array = something; function trap() { function exec() { foo(obj_array); } return exec; } setTimeout(trap(), 1000);
or even:
var obj_array = something; function trap() { foo(obj_array); } setTimeout(trap, 1000);
and finally thicken to:
var obj_array = something; setTimeout(function() { foo(object_array); }, 1000);
EDIT: My functions (or at least 1 iteration of them I found in the backup here)
Function.prototype.createDelegate = function(inst, args) { var me = this; var delegate = function() { me.apply(inst, arguments); } return args ? delegate.createAutoDelegate.apply(delegate,args) : delegate; }; Function.prototype.createAutoDelegate = function() { var args = arguments; var me = this; return function() { me.apply({}, args); } };
Given:
function test(a, b) { alert(a + b); }
APPLICATION:
setTimeout(test.createAutoDelegate(1, 2), 1000);
OR GIVEN:
var o = { a:1, go : function(b) { alert(b + this.a); }}
APPLICATION:
setTimeout(o.go.createDelegate(o,[5]), 1000); //or setTimeout(o.go.createDelegate(o).createAutoDelegate(5), 1000);