I have a function called f0 having some parameters. When i call it, it calls some other functions with some parameters(for example the same parameters). The problem is, can i add somehow these functions dynamically?
A simple solution would be something like this:
var callf1=true;
var callf2=true;
var callf3=true;
function f1(params){
//some code
}
function f2(params){
//some other code
}
function f3(params){
//some code
}
function f0(params){
if(callf1){
f1();
}
if(callf2){
f1();
}
if(callf3){
f1();
}
}
function mymain(){
f0(pa开发者_如何学编程rams);
}
setInterval("mymain()",5000);
This option is much time consuming because every time it has to check the variables. Could i use somehow the trigger option in JQuery using runtime and giving parameters?
I would be glad if you can recommend me an easier and simpler solution.
The current solution is not time consuming since checking some variables once in 5 seconds is far from complicated for the computer. So you probably would want to stick with the current solution - the only thing I would reccomend would be ditching the string-command from setInterval
from:
setInterval("mymain()",5000);
to:
setInterval(mymain,5000);
This way you would bypass an eval
statement which is probably much more time consuming than a variable check would ever be.
精彩评论