使用双括号在Javascript中调用函数 [英] Function calling in Javascript with double brackets

查看:311
本文介绍了使用双括号在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>

使用()()带有函数名?

推荐答案

如果 hi 返回了一个函数而不是它的名字,比如

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆