[ES6] 05. The leg keyword -- 3. Block Scope
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的更多相关文章
- Closure - Mimicking block scope
The basic syntax of an anoymous function used as a block scope (often called a private scope) is as ...
- [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 ...
- [ES6] 03. The let keyword -- 1
var message = "Hi"; { var message = "Bye"; } console.log(message); //Bye The mes ...
- YDKJ 读书笔记 01 Function vs. Block Scope
Introduction 本系列文章为You Don't Know JS的读书笔记. 书籍地址:https://github.com/getify/You-Dont-Know-JS Scope Fro ...
- ES6 Syntax and Feature Overview
View on GitHub Note: A commonly accepted practice is to use const except in cases of loops and reass ...
- [ES6] 22. Const
'const' keyword is for creating a read only variable, something you can never change once created. ' ...
- You Don't Know JS: Scope & Closures (第一章:什么是Scope)
Content What is Scope? Lexical Scope Function Vs. Block Scope Hoisting Scope Closures Appendix: Dyna ...
- ES6/ES2015常用知识点和概念
越来越多的开源库开始使用ES2015来构建代码了,大家知道ES6=ES2015,ES6在2015年被ECMAScript标准化组织approve,各大浏览器厂商要完全支持ES6的强大功能还须一些时日, ...
- JavaScript ES6新特性介绍
介绍 ES6:ECMScript6 首先,一个常见的问题是,ECMAScript 和 JavaScript 到底是什么关系? ECMAScript是一个国际通过的标准化脚本语言: JavaScript ...
随机推荐
- 洛谷P3066 [USACO12DEC] 逃跑的Barn [左偏树]
题目传送门 逃跑的Barn 题目描述 It's milking time at Farmer John's farm, but the cows have all run away! Farmer J ...
- sublime text3 常用插件
1.代码格式化:html-css-js prettify 2.代码注释:docBlockr 3.代码管理:git.gitGutter 4.快速编辑:emmet 5.代码匹配:bracket highl ...
- 前缀和:CodeForces 932B Recursive Queries
Description Let us define two functions f and g on positive integer numbers. You need to process Q q ...
- 「SCOI2016」萌萌哒
「SCOI2016」萌萌哒 题目描述 一个长度为 \(n\) 的大数,用 \(S_1S_2S_3 \ldots S_n\) 表示,其中 \(S_i\) 表示数的第 \(i\) 位,\(S_1\) 是数 ...
- luoguP4320 道路相遇 圆方树
标题已经告诉你怎么做了..... 两点间的圆点个数即为所求 建出圆方树后打个树剖求$lca$就行..... 复杂度$O(n + q \log n)$ #include <cstdio> # ...
- [HNOI2018]道路 --- 树形DP
[HNOI2018]道路 题目描述: W 国的交通呈一棵树的形状.W 国一共有 \(n-1\) 个城市和 \(n\) 个乡村, 其中城市从 \(1\) 到 \(n-1\) 编号,乡村从 \(1\) 到 ...
- Java Queue的测试
上传图片没上去,提交的时候已经结束 代码链接
- struts2漏洞S2-046修复解决方案
项目验收通过半年之后, 甲方找了一些网络砖家用工具扫描我司做的社保卡申领系统, 找到了struts2漏洞S2-046, 真是服了, 只知道struts2有bug, 现在才知道它漏洞. 砖家们给出了修复 ...
- 【转载】Unicode 编码表
转载备忘:Unicode 编码表 具体请移步: http://www.cnblogs.com/chenwenbiao/archive/2011/08/17/2142718.html
- 11.m进制转十进制
Strlen是字符串有多长就是多长,包括所有的元素和\0这个结束符 题目描述 Description 将m进制数n转化成一个十进制数 m<=16 题目保证转换后的十进制数<=100 输入描 ...