1
0
mirror of https://github.com/ruanyf/es6tutorial.git synced 2025-05-25 03:02:21 +00:00

Merge pull request #10 from hotoo/gh-pages

更新了函数作用域在其所在块级作用域的表述。
This commit is contained in:
ruanyf 2014-05-23 22:38:32 +08:00
commit 1cc1735c8d
2 changed files with 11 additions and 11 deletions

View File

@ -11,7 +11,7 @@ ES6新增了let命令用来声明变量。它的用法类似于var但是
var b = 1; var b = 1;
} }
a // ReferenceError: a is not defined. a // ReferenceError: a is not defined.
b //1 b //1
``` ```
@ -102,10 +102,10 @@ function f1() {
```javascript ```javascript
// IIFE写法 // IIFE写法
(function () { (function () {
var tmp = ...; var tmp = ...;
... ...
}()); }());
// 块级作用域写法 // 块级作用域写法
{ {
@ -115,7 +115,7 @@ function f1() {
``` ```
另外ES6也规定函数的作用域为其所在的块级作用域 另外ES6也规定函数本身的作用域,在其所在的块级作用域之内
```javascript ```javascript

View File

@ -30,13 +30,13 @@ target // {a:1, b:2, c:3}
``` ```
注意,如果源对象与目标对象有同名属性,则前者会覆盖后者。 注意,如果目标对象与源对象有同名属性,或多个目标对象有同名属性,则前者会覆盖后者。
```javascript ```javascript
var target = { a: 1, b: 1 }; var target = { a: 1, b: 1 };
var source1 = { b: 2 }; var source1 = { b: 2, c: 2 };
var source2 = { c: 3 }; var source2 = { c: 3 };
Object.assign(target, source1, source2); Object.assign(target, source1, source2);
@ -81,14 +81,14 @@ var o = Object.setPrototypeOf({}, null);
function (obj, proto) { function (obj, proto) {
obj.__proto__ = proto; obj.__proto__ = proto;
return obj; return obj;
} }
``` ```
**3Object.getPrototypeOf()** **3Object.getPrototypeOf()**
与setPrototypeOf()配套还有getPrototypeOf()用于读取一个对象的prototype对象。 该方法与setPrototypeOf()配套用于读取一个对象的prototype对象。
```javascript ```javascript
@ -177,7 +177,7 @@ ES6引入了一种新的原始数据类型symbol。它通过Symbol函数生成
var mySymbol = Symbol('Test'); var mySymbol = Symbol('Test');
mySymbol.name mySymbol.name
// Test // Test
typeof mySymbol typeof mySymbol
@ -206,7 +206,7 @@ function f(w) {
case w3: case w3:
... ...
} }
} }
``` ```
@ -214,7 +214,7 @@ function f(w) {
由于这种特点Symbol类型适合作为标识符用于对象的属性名保证了属性名之间不会发生冲突。如果一个对象由多个模块构成这样就不会出现同名的属性。 由于这种特点Symbol类型适合作为标识符用于对象的属性名保证了属性名之间不会发生冲突。如果一个对象由多个模块构成这样就不会出现同名的属性。
Symbol类型作为属性名可以被遍历Object.getOwnPropertySymbols()和Object.getOwnPropertyKeys()都可以获取该属性。 Symbol类型作为属性名可以被遍历Object.getOwnPropertySymbols()和Object.getOwnPropertyKeys()都可以获取该属性。
```javascript ```javascript