Javascript 如何从函数内部调用函数?
如何将函数放入函数中Javascript 如何从函数内部调用函数?,javascript,Javascript,如何将函数放入函数中 do_something(){ alert('do something'); } also_do_something = function(){ alert('also do something'); }; inp.onclick = function(){ do_something(); // this don't work also_do_something; }; 要调用函数,必须添加括号: inp.onclick =
do_something(){
alert('do something');
}
also_do_something = function(){
alert('also do something');
};
inp.onclick = function(){
do_something();
// this don't work
also_do_something;
};
要调用函数,必须添加括号:
inp.onclick = function(){
do_something();
also_do_something();
};
还有,有些东西是函数引用,你不需要调用它,你只需要得到它。如果要调用,还可以使用_do_something调用函数,需要添加括号:
inp.onclick = function(){
do_something();
// this don't work
also_do_something();
};
我很想听听是什么让你把括号放在“做什么”而不是“也做什么”?Yo dawg我们听说你喜欢函数…@nEEbz。。。这可能与声明还_do_something=函数有关,认为您需要做的就是调用还_do_something?我不知道发生了什么尽管@clarkk的头。。。只是一个面团。。我甚至没想到。。呵呵