node.js中的回调函数_Node JS中的匿名函数

node.js中的回调函数

Functions are the very basic and fundamental topic of any programming language. Understanding them in great detail is very much necessary for any programmer or coder.

函数是任何编程语言中非常基本的主题。 对于任何程序员或编码人员而言,非常详细地了解它们都是非常必要的。

Thus, in this article, I will throw light on anonymous functions in JavaScript.

因此,在本文中,我将介绍JavaScript中的匿名函数。

They are a very strong tool for generating concise codes and are very commonly seen in JavaScript libraries.

它们是生成简明代码的强大工具,在JavaScript库中很常见。

Example:

例:

(function(food) {
    if (food === "cookies") {
        console.log("More please");
    } else if (food === "cake") {
        console.log("Yum yum");
    }
})("cookies");

Output

输出量

anonymous function output | Node JS

Explanation:

说明:

It might seem to be very confusing on first glance, but it is not so.

乍一看似乎很令人困惑,但事实并非如此。

In line number 7 we are just calling a function and passing cookies as an argument to it. But the function we are calling is anonymous i.e. it does not have a name.

在第7行中,我们只是调用一个函数并将cookie作为参数传递给它。 但是我们正在调用的函数是匿名的,即它没有名称。

So instead of using a function reference we are defining the function or using a function expression.

因此,我们不用定义函数引用,而是定义函数或使用函数表达式。

Also, pay attention that extra set of parenthesis is very much necessary for these kinds of function calling otherwise java interpreter won't be able to identify it as a function.

另外,请注意,对于此类函数调用,非常需要额外的括号集,否则java解释器将无法将其识别为函数。

翻译自: https://www.includehelp.com/node-js/anonymous-function.aspx

node.js中的回调函数

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值