那些拥有 Chrome 30.0.1599.14 dev 的人似乎对这个新功能很有天赋:
String(Array.prototype.find); // "function find() { [native code] }"
但是,我还没有找到关于此添加的任何引用。从我的测试来看,它似乎接受参数 a-la some
、every
等等:
array.some(callback[, thisObject]);
和callback
是那种通常的回调函数:
function([item[, index[, array]]]) {
...
}
当传递“正确的”item
时,该函数应返回 true
,以便该 item 成为 find
返回的值。例如:
Array.prototype.slice.call(document.getElementsByTagName("*"))
.find(function(element) {return element.id === "content";});
这是一种重新定义 document.getElementById
的奇怪方法,除非找不到该项目 find
返回 undefined
而不是 空
。
如果这个函数可以接受初始索引,或者如果可以有像 lastFind
这样的双重函数从末尾解析数组,那就太好了。
有没有人已经看过这个函数并能告诉我在哪里可以找到它的规范?
最佳答案
这是 ECMA 脚本 6。这是一个 HTML version of the ES6 spec .这是 specific section for Array.prototype.find()
.
更新:另外,the Chromium bug for Array.prototype.find implementation .
关于javascript - Array.prototype.find,它的规范是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18443447/