开发者

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 ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜