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

news/2024/7/19 16:26:06 标签: javascript, python, lambda, java, 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

输出量

js/Images/anonymous-function-output.jpg" alt="anonymous function output | Node JS" style="outline: none;" />

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中的回调函数


http://www.niftyadmin.cn/n/1253901.html

相关文章

isd1802_ISD的完整形式是什么?

isd1802ISD:国际用户拨号 (ISD: International Subscriber Dialing) ISD is an abbreviation of International Subscriber Dialing. It is also called as "International Direct Dialing (IDD)". This term stated as an International telephone call …

椭圆曲线密码学导论pdf_密码学导论

椭圆曲线密码学导论pdf安全目标 (Security Goals) Lets discuss the three security goals... 让我们讨论三个安全目标... 1) Confidentiality: 1)保密性: Confidentiality is probably the most common aspect of information security, we need to protect it. …

css下拉菜单样式_CSS样式下拉菜单

css下拉菜单样式Introduction: 介绍: As we all know that the styling website or web pages are an important aspect of web development. One must put utmost attention to the styling of their web pages or websites as this enhances the appearance of t…

二叉树右视图_二叉树的底视图

二叉树右视图Problem statement: 问题陈述: Given a binary tree, print the bottom view from left to right. 给定一棵二叉树,从左到右打印底视图。 Example: 例: In the above example the bottom view is: 2 5 6 11 4 9 (left to righ…

网卡聚合bind模式_BIND的完整形式是什么?

网卡聚合bind模式绑定:伯克利互联网名称域 (BIND: Berkeley Internet Name Domain) BIND is an abbreviation of "Berkeley Internet Name Domain". BIND是“伯克利Internet名称域”的缩写 。 It is a well-known extensively used domain name system s…

linux混合命令_Linux命令(混合)能力问题和解答

linux混合命令This section contains Aptitude Questions and Answers on Linux Commands (Mixed). 本节包含有关Linux命令的 Aptitude问答(混合) 。 1) Which of the following command is used to display the list of available groups in the system? listgrouplistgeten…

vigenere密码_密码学中的Vigenere密码

vigenere密码The Vigenere cipher is one of the well-known techniques used for encrypting the data, which was proposed by Friedrich Kasiski in 1863. Although the Caeser cipher, which was amongst the firstly developed encryption techniques which gave us the i…

在Python中复制和重命名文件

Using shutil (shell utilities) module, file operation such as copy, rename, move, etc is very handy. To copy and rename, there are two approaches: 使用shutil(shell实用程序)模块 ,文件操作(例如复制,重命名,移动等)非常方便。 要…