[英]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.