标签:
注意:
1. Node环境下,--harmony参数启用ES6新特性,许多新特性只有在strict mode下才生效,因此使用"use strict"或者--use_strict,否则harmony没有被启用;
1. 块级作用域(Block scope)
// Block scope function f1(){ console.log("Outside."); } (function(){ if(false){
// f1定义在if {}之内 function f1() { console.log("Inside."); } } f1(); }());
ES5中:
1. strict mode: 将会报错:In strict mode code, functions can only be declared at top level or immediately within another function.(函数只能声明在Glocal scope或者函数里的最外层)
2. non-strict mode: 输出:"Inside";
ES6中:
1. strict mode: 输出:"Outside",(node环境下使用命令:node --harmony --use_strict 1_blockScope.js,使用node 1_blockScope.js --harmony命令,harmony没有起作用)
2. non-strict mode: 输出:"Inside";(根据上面第一条:non-strict mode下不启用harmony)
因为ES6中,出现了块级作用域,导致上面的代码在ES6 context的strict mode中是有意义的;
标签:
原文地址:http://www.cnblogs.com/diydyq/p/4190214.html