如果您在控制台中运行此代码:
(function(){
test: "hello";
})();
Run Code Online (Sandbox Code Playgroud)
甚至这个:
test: "hello";
Run Code Online (Sandbox Code Playgroud)
没有任何反应,也没有错误.为什么?这很简单,"嗯......这是JavaScript ......处理它."?
对于上下文,我公司的一些实习生偶然写了类似的东西(意思是使用'=').当面对它可能会抛出错误时,他们说它没有.
而现在我很好奇.
Que*_*tin 12
JavaScript中的任何语句(包括创建字符串文字然后不对其执行任何操作的语句)都可以有标签(请参阅ECMAScript 2015或MDN).除非你有想要break或continue来自的嵌套循环,否则它没什么用处.
(function(){ // Begin function expression
test: // Label statement
"hello"; // Create a string and do nothing with it
})(); // End function expression and invoke the created function
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
74 次 |
| 最近记录: |