Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这可能吗?例子:
var parts = [1,2,3,4,5]; for (part of parts) { console.debug(part); }
我想检测是否可以这样做。
你总是可以尝试捕捉这些东西。但是你也需要eval,因为一些 javascript 引擎会提早出现 SyntaxError。
eval
try { eval("for (var i of []);"); console.log("yep"); } catch(ex) { console.log("nope"); }
在 Firefox ("yep") 和 Chrome ("nope") 中测试。