本文介绍了在ES6中,什么是新规范,即“块级功能声明".意思是?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要查看es6兼容性表,以尝试学习这里.

I'm going down the es6 compatibility table trying to learn Here.

绑定部分中,其显示块级函数声明?".除了正式的规范关于单词的组合.

in the bindings section it says "block-level function declaration?". I'm unable to find any blogs or documentation besides the offical spec on that combinations of words.

问题:什么是块级函数声明"?

Question: What is "block-level function declaration" referring to?

推荐答案

示例kangax正在测试:

the example kangax is testing for:

alert(function(){
    'use strict';
    function f() { return 1; }
    {
      function f() { return 2; }
    }
    return f() === 1;
}());

这意味着函数提升"的行为与let(vs var)相同.

it means that function "hoisting" behaves the same way as let (vs var).

在ES5中,括号是装饰",除非它们出现在foriftry等几个关键字之后,因此,第二个f()将占据"第一个,但在第一个中与ES6兼容的运行时,第二个f()是该块的私有对象,因此不会替换第一个函数定义的名称f.

In ES5, braces were "decoration", unless they appeared after a few keywords like for, if, try, etc. so, the 2nd f() would "clobber" the 1st, but in ES6-compat runtimes, the 2nd f() is private to the block and thus doesn't replace the name f defined by the 1st function.

在ES6中,大括号({ ... })表示一个块,即使没有前面的关键字也是如此.就是说,我在ES6代码中看不到很多任意的块,可能仅仅是由于缺乏实践,无知,或者仅仅是由于缺乏需要;函数作用域在JS中效果很好.

In ES6 braces ({ ... }) mean a block, even without a preceding keyword. That said, i don't see many arbitrary blocks in ES6 code, maybe just from lack of practice, ignorance, or perhaps just from lack of need; function scope works pretty well in JS.

这篇关于在ES6中,什么是新规范,即“块级功能声明".意思是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!