Javascript,严格模式-这些花括号不';t似乎不是一个对象文字,它们是做什么的?

Javascript,严格模式-这些花括号不';t似乎不是一个对象文字,它们是做什么的?,javascript,function,curly-braces,Javascript,Function,Curly Braces,我无法理解这个语法,在“use strict”之后的一组大括号做了什么 它只是一个常规的块。在Javascript中,这样的块没有特定的作用域。它们按照代码的流程进行操作 这意味着您可以安全地忽略(或删除)它们,而不会对代码产生任何影响 function test(a, b) { 'use strict'; // no curly braces here var c = {}; Array.prototype.slice // neither here

我无法理解这个语法,在“use strict”之后的一组大括号做了什么


它只是一个常规的块。在Javascript中,这样的块没有特定的作用域。它们按照代码的流程进行操作

这意味着您可以安全地忽略(或删除)它们,而不会对代码产生任何影响

function test(a, b) {
   'use strict';
    // no curly braces here
      var c = {};
      Array.prototype.slice
   // neither here

   ... //more stuff
   return a;
} //one and the same thing

您可以在中阅读有关Javascript中作用域的更多信息。

它们引入了block语句。由于JavaScript中的块没有作用域,所以这样做没有多大意义。请注意,即将发布的ECMAScript 6规范允许使用
let
语句的块作用域变量。由于目前只在Firefox中支持,所以在Firefox特定代码之外没有真正的理由这样做。另见
function test(a, b) {
   'use strict';
    // no curly braces here
      var c = {};
      Array.prototype.slice
   // neither here

   ... //more stuff
   return a;
} //one and the same thing