javascript - js : why use Array. prototype.map.call 而不是 map()?

标签 javascript arrays

<分区>

这是 casperjs JS 的摘录:

function getPrices() {
  var price = document.querySelectorAll('#InvoiceDetailGrid tbody');
  return Array.prototype.map.call(price, function(elem) {
    return elem.textContent;
  });
}

为什么要使用 Array.prototype.map.call:不能简单地使用: price.map() ?

最佳答案

因为price是一个类数组(NodeList)对象,而不是数组。

使用 Array.prototype.map,您采用 Array 的方法并将类似数组的对象用作映射对象。

关于javascript - js : why use Array. prototype.map.call 而不是 map()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40545193/

相关文章:

javascript - HTML5/JS - 启动多个 webworker

javascript - 当我在 Node js 中创建后调用时,为什么 Watson-conversation 对任何请求返回相同的默认响应

javascript - 防止通过 CSS/JS/等在 Google Chrome 中重新绘制

javascript - 如何在给定点直接或通过另一个元素的空腔检测哪个元素可见/位于顶部?

ruby-on-rails - Ruby-如何通过条件最大的多个键检索数组组中的总和

javascript - 更改从 JSON 数组创建的列表中的项目

各种 API 中的 Javascript 链接语法?

javascript - 配置从 node_modules 读取的 requirejs

javascript - 为 Angular 动态数据生成嵌套结构

java - 试图掌握从 0 到 99999 对数字进行排序的算法的概念