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.
If you want to pass more than one parameter to the URL,use data as data:{id:'123' , name:"MyName"} where the 123 is the value of the parameter id myName is the value for the parameter name the value here can be string or variable having the value to be passed.
We cannot pass the function as an argument to another function. But we can pass the reference of a function as a parameter by using a function pointer. This process is known as call by reference as the function parameter is passed as a pointer that holds the address of arguments.
Functions can be passed into other functionsFunctions, like any other object, can be passed as an argument to another function.
Functions in the functional programming paradigm can be passed to other functions as parameters. These functions are called callbacks. Callback functions can be passed as arguments by directly passing the function's name and not involving them.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With