传递一个函数作为参数,然后在jquery函数中执行它 [英] pass a function as a parameter and then execute it in a jquery function
问题描述
我有一个像这样的函数:
function setSomething(){
make some stuff;
}
,然后执行另一个函数:
generalFunction(par1,par2,par3){
do other stuff;
在par3中调用的执行函数;
}
好吧,如果我写这样的东西不起作用: p>
c = setSomething();
generalFunction(a,b,c);
那么,调用一个函数作为另一个函数的参数然后在里面执行的方法是什么? / p>
我希望我很清楚。
任何帮助都会感激。
提前感谢您的关注。
省略括号,然后可以调用参数作为您的generalFunction函数内的函数。
setSomething(){
//做其他东西
}
generalFunction(par1,par2,par3){
// do stuff ...
//可以调用参数一个函数(因为它是!)
par3();
}
generalFunction(a,b,setSomething);
I was wondering which is the way to make this simple (and maybe stupid) thing with jQuery.
I have a function like this:
function setSomething() {
make some stuff;
}
and then another function like this:
generalFunction(par1, par2, par3) {
do other stuff;
execute function called in par3;
}
Well, if I write something like this it doesn't work:
c=setSomething();
generalFunction(a, b, c);
So what's the way to call a function as a parameter of another function and then execute it inside?
I hope I was clear enough.
Any help will be appreciated.
Thank you in advance for your attention.
leave out the parentheses , you can then call the parameter as a function inside your "generalFunction" function.
setSomething(){
// do other stuff
}
generalFunction(par1, par2, par3) {
// do stuff...
// you can call the argument as if it where a function ( because it is !)
par3();
}
generalFunction(a, b, setSomething);
这篇关于传递一个函数作为参数,然后在jquery函数中执行它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!