Reputation: 1232
I'm trying to figure out how to pass an argument to one function, which is actually a second function. Hard to explain so here is some sample code:
keyDownEvent("#thisID",nameOfFunctionToRunOnOpen);
function keyDownEvent(id, openFunction) {
$(id).dialog( {
close: focusOnInput(),
open: nameOfFunctionToRunOnOpen,
modal: true,
show: "clip",
hide: "fade"
});
}
Everything else is standard for my .dialog() calls, just want to modify what happens on Open. Any idea how this can be achieved?
Upvotes: 1
Views: 149
Reputation: 30991
You can simply pass the function to your second function. Functions are objects in JavaScript and can be saved in variables:
function outer(someOtherFunction) {
someOtherFunction();
}
outer(function () {
alert('inner function');
});
Upvotes: 0
Reputation: 285077
Just use an anonymous function:
function keyDownEvent(id, openFunction) {
$(id).dialog( {
close: focusOnInput(),
open: function(){openFunction(someArgument);},
modal: true,
show: "clip",
hide: "fade"
});
}
Upvotes: 1
Reputation: 2700
Your second parameter should be given an actual function object and not just the name of the function in a string.
Upvotes: 0