[英]How to call a function from within 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;
};
要調用函數,必須添加括號:
inp.onclick = function(){
do_something();
also_do_something();
};
also_do_something
是函數引用,您無需調用它,只需獲取它即可。 如果您想打電話,請使用also_do_something ()
要調用函數,您需要添加括號:
inp.onclick = function(){
do_something();
// this don't work
also_do_something();
};
聽到是什么使您在do_something()
而不是also_do_something
加上括號會很有趣?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.