How to call a function from within a function?
how can you开发者_开发百科 put a function in a function?
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;
};
To call a function, you must add the parentheses :
inp.onclick = function(){
do_something();
also_do_something();
};
also_do_something
is a function reference, you don't call that, you just get it. If you want to call, use also_do_something ()
to call a function, you need to add the parenthesis:
inp.onclick = function(){
do_something();
// this don't work
also_do_something();
};
would be interesting to hear what made you put parenthesis in do_something()
and not in also_do_something
?
精彩评论