//在找不到标签的函数错误中打破不使用标签
var a = 10 ;
function myfn(){
if(a===15){
break stoplabel;
}
else{
console.log(a);
a++;
stoplabel:myfn();
}
}
myfn();
答案 0 :(得分:1)
您只能在break stoplabel;
代码块中使用stoplabel:
。
例如:
var cars = ["BMW", "Volvo", "Saab", "Ford"];
var text = [];
list: {
text.push(cars[0]);
text.push(cars[1]);
text.push(cars[2]);
break list;
text.push(cars[3]);
text.push(cars[4]);
text.push(cars[5]);
}
console.log(text);
您可以按以下方式更改代码:
var a = 10 ;
function myfn(){
if(a===15){
return;
}
else{
console.log(a);
a++;
myfn();
}
}
myfn();