문제

Is this possible? Example:

var parts = [1,2,3,4,5];
for (part of parts) {
    console.debug(part);
}

I want to detect if doing this is possible.

도움이 되었습니까?

해결책

You can always try-catch such stuff. But you need eval as well, as some javascript engines will bail with a SyntaxError early.

try {
  eval("for (var i of []);");
  console.log("yep");
} catch(ex) {
  console.log("nope");
}

Tested in Firefox ("yep") and Chrome ("nope").

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top