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