In ES6, IIFE is not necessary:

// IIFE写法
(function () {
var tmp = ...;
...
}()); // 块级作用域写法
{
let tmp = ...;
...
}

另外,ES6也规定,函数本身的作用域,在其所在的块级作用域之内

function f() { console.log('I am outside!'); }
(function () {
if(false) {
// 重复声明一次函数f
function f() { console.log('I am inside!'); }
} f();
}());

上面代码在ES5中运行,会得到“I am inside!”,但是在ES6中运行,会得到“I am outside!”

(function () {
if(true) {
// 重复声明一次函数f
function f() { console.log('I am inside!'); }
f();
} }());
function f() { console.log('I am outside!'); }

上面代码在ES6中运行,会得到“I am inside!”

[ES6] 05. The leg keyword -- 3. Block Scope的更多相关文章

  1. Closure - Mimicking block scope

    The basic syntax of an anoymous function used as a block scope (often called a private scope) is as ...

  2. [ES6] 04. The let keyword -- 2 Fiald case

    Fiald case 1: let can work in it's block { let a = 10; var b = 1; } a // ReferenceError: a is not de ...

  3. [ES6] 03. The let keyword -- 1

    var message = "Hi"; { var message = "Bye"; } console.log(message); //Bye The mes ...

  4. YDKJ 读书笔记 01 Function vs. Block Scope

    Introduction 本系列文章为You Don't Know JS的读书笔记. 书籍地址:https://github.com/getify/You-Dont-Know-JS Scope Fro ...

  5. ES6 Syntax and Feature Overview

    View on GitHub Note: A commonly accepted practice is to use const except in cases of loops and reass ...

  6. [ES6] 22. Const

    'const' keyword is for creating a read only variable, something you can never change once created. ' ...

  7. You Don't Know JS: Scope & Closures (第一章:什么是Scope)

    Content What is Scope? Lexical Scope Function Vs. Block Scope Hoisting Scope Closures Appendix: Dyna ...

  8. ES6/ES2015常用知识点和概念

    越来越多的开源库开始使用ES2015来构建代码了,大家知道ES6=ES2015,ES6在2015年被ECMAScript标准化组织approve,各大浏览器厂商要完全支持ES6的强大功能还须一些时日, ...

  9. JavaScript ES6新特性介绍

    介绍 ES6:ECMScript6 首先,一个常见的问题是,ECMAScript 和 JavaScript 到底是什么关系? ECMAScript是一个国际通过的标准化脚本语言: JavaScript ...

随机推荐

  1. Kail Linux渗透测试教程之在Metasploit中扫描

    Kail Linux渗透测试教程之在Metasploit中扫描 在Metasploit中扫描 在Metasploit中,附带了大量的内置扫描器.使用这些扫描器可以搜索并获得来自一台计算机或一个完整网络 ...

  2. PHP 笔记——基础

    一.PHP 简介 1. PHP是什么 PHP:Hypertext Preprocessor,即超文本预处理器. PHP是一种跨平台.服务器端.可嵌入HTML文件的脚本语言. 嵌入了PHP代码的HTML ...

  3. codevs 1058 合唱队形 2004年NOIP全国联赛提高组

    1058 合唱队形 2004年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold   题目描述 Description N位同学站成一排,音 ...

  4. luoguP3600 随机数生成器 期望概率DP + DP优化

    这篇题解更像对他人题解的吐槽和补充? 考虑答案 $E[X] = \sum\limits_{i = 1}^{x} i P(X = i)$ $P(X = i)$不好求................(其实 ...

  5. bzoj 1231: [Usaco2008 Nov]mixup2 混乱的奶牛 -- 状压DP

    1231: [Usaco2008 Nov]mixup2 混乱的奶牛 Time Limit: 10 Sec  Memory Limit: 162 MB Description 混乱的奶牛 [Don Pi ...

  6. 提示框框架KVNProgress介绍

    gitHub上面有很多显示加载进度的框架,这里我们介绍一下KVNProgress框架,KVNProgress是一个可以完全定制的HUD(指示器),你可以设置加载进度的画面是否全屏,可以自己修改进度显示 ...

  7. 更新teaching中fdSubjectID为null的老数据

    UPDATE wkwke.tbTeachingV3 teaching SET teaching.fdSubjectID = (                    SELECT fdValue FR ...

  8. mysql localhost登录和tcp/ip登录 strace

    http://blog.itpub.net/15480802/viewspace-1755100/

  9. js继承——到继承结束

    说到继承,其它语言里可能有两种: 接口继承是继承方法签名,而实现继承则继承实际方法.ES函数没有签名,不能实现接口继承,只支持实现继承,而实现继承主要依靠原型链.(这两句话,说来轻松,理解来不易,且行 ...

  10. 可用Active Desktop Calendar V7.86 注册码序列号

    可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code:  DC8EC-16985-F26A6