使用双括号在Javascript中调用函数 [英] Function calling in Javascript with double brackets
本文介绍了使用双括号在Javascript中调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我用双括号调用函数 hi()()
时,该函数显示 hi
输出,它也会提出错误说, hi
不起作用。
When I call function hi()()
with double brackets the function displays hi
output and it will also give error saying, that hi
is not function.
<html>
<head></head>
<script>
function hello()
{
document.write("hello");
}
function hi()
{
document.write("hi");
return "hello";
}
hi()();
</script>
</html>
使用()()$ c $是什么意思c>带有函数名?
推荐答案
如果 hi $ c,双括号将非常有用$ c>返回了一个函数而不是它的名字,比如
The double parenthesis would have been useful if hi
had returned a function instead of its name, like in
function hi(){
return hello;
}
hi()();
这可能是意图的原因。
这篇关于使用双括号在Javascript中调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文