The following seams to work, at least when tested via console, please let me know if its not the correct way of doing things:
function test1(x){
x();
}
function test2(){
console.log('test2 fired');
}
test1(test2);
Will result in console outputting:
test2 fired
So assuming the above is correct, how do i pass in a function name WITH parameters? Do they need to be passed in individually? Like this:
function test1(x,p,r){
x(p,r);
}
function test2(p,r){
console.log('test2 fired - p: '+p+' | r: '+r);
}
While the above should work, is there to pass in the parameters as part of ‘x’ rather then as individual params?
To give a bit of insight, what we are trying to do is basically if a condition is met inside “test1”, execute a function, that takes parameters. To simplify further, imagine test1 creates a DOM object, and we want to attach a onerror property to this DOM object. If this DOM objects fires onerror, invoke our ajax function, which takes parameters (url, querystring, method, etc). We are hoping on being able to do this without any intermediate functions.
Thank you kindly.
I suppose this doesn’t meet you condition on no intermediate functions, but the simple way of accomplishing this is passing an anonymous function: