Node.js的是Array.map()异步? [英] Is Node.js Array.map() asynchronous?

查看:410
本文介绍了Node.js的是Array.map()异步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能指望nodeIDs映射完成每DoSomething的()被调用的时候?

Can I count on nodeIDs mapping is completed every time doSomething() is called?

nodeIDs = $.map(nodeIDs, function(n){
    return n.match(/\d+$/);
});
doSomething(nodeIDs);

我想在node.js中所有的回调都是异步的?我没有读一般的编程了一篇文章,回调可能是同步的,但我不知道的node.js?

I thought all callbacks in node.js are asynchronous? I did read an article on general programming that callback could be synchronous but I am not sure about node.js?

推荐答案

的JavaScript也是一种函数式编程语言。你在这里什么是«高阶函数»,这需要一个函数作为参数的函数。高阶函数是同步的。

JavaScript is also a functional programming language. What you have here is a «higher order function», a function which takes a function as a parameter. Higher order functions are synchronous.

来源:

  • Functional Programming
  • Higher order functions in JavaScript

地图()是一个高阶函数的一个典型例子。它需要一个功能,并将其应用到数组的所有元素。该定义听起来很«功能»。此功能也不会由节点提供的。它是由 MDN Array.prototype.map()记载并指定由的ECMAScript 5.1

map() is a typical example of a higher order function. It takes a function and applies it to all elements of an array. The definition sounds very «functional». This function is also not provided by Node. It is documented by MDN Array.prototype.map() and specified by ECMAScript 5.1.

要回答你的问题:是的, DoSomething的(nodeIDs)被称为所有元素都被应用

To answer your question: Yes, doSomething(nodeIDs) is called after all elements have been applied.

这篇关于Node.js的是Array.map()异步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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