0
例如返回:如何从一个更高的功能
function foo() {
someArray.map(bar) {
if (whatever)
return; // I want to return from the foo function
return bar.something // Here I return to map function
}
}
这是我目前的解决方案:
let flag = false
function foo() {
someArray.map(bar) {
if (whatever){
flag = true
}
return bar.something // Here I return to map function
}
}
if (flag === true) {
return;
}
我不知道是否有更好的办法?
我猜你想打破“地图”功能。你不能那样做。 –
可能是http://stackoverflow.com/questions/12260529/break-statement-in-javascript-array-map-method – Cr4xy
使用正确的工具来完成这项工作。你想'找到',而不是'地图'。 – Bergi