Skip to content

Commit 349e0fd

Browse files
committed
fix error
1 parent 86eca41 commit 349e0fd

File tree

7 files changed

+36
-30
lines changed

7 files changed

+36
-30
lines changed

docs/arraybuffer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ xhr.open('GET', someUrl);
782782
xhr.responseType = 'arraybuffer';
783783

784784
xhr.onload = function () {
785-
var let arrayBuffer = xhr.response;
785+
let arrayBuffer = xhr.response;
786786
// ···
787787
};
788788

docs/decorator.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ obj.foo() // "foo"
455455

456456
## Trait
457457

458-
Trait也是一种修饰器,功能与Mixin类型,但是提供更多功能,比如防止同名方法的冲突、排除混入某些方法、为混入的方法起别名等等。
458+
Trait也是一种修饰器,效果与Mixin类似,但是提供更多功能,比如防止同名方法的冲突、排除混入某些方法、为混入的方法起别名等等。
459459

460460
下面采用[traits-decorator](https://github.com/CocktailJS/traits-decorator)这个第三方模块作为例子。这个模块提供的traits修饰器,不仅可以接受对象,还可以接受ES6类作为参数。
461461

@@ -478,7 +478,7 @@ obj.foo() // foo
478478
obj.bar() // bar
479479
```
480480

481-
上面代码中,通过traits修饰器,在MyClass类上面“混入”了TFoo类的foo方法和TBar对象的bar方法
481+
上面代码中,通过traits修饰器,`MyClass`类上面“混入”`TFoo`类的`foo`方法和`TBar`对象的`bar`方法
482482

483483
Trait不允许“混入”同名方法。
484484

docs/function.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -471,13 +471,19 @@ bar.name // "baz"
471471
bar.name // "baz"
472472
```
473473

474-
只有具名函数才有`name`这个属性,匿名函数是没有的
474+
`Function`构造函数返回的函数实例,`name`属性的值为“anonymous”
475475

476476
```javascript
477-
'name' in (function () {})
478-
// false
479-
'name' in (() => {})
480-
// false
477+
(new Function).name // "anonymous"
478+
```
479+
480+
`bind`返回的函数,`name`属性值会加上“bound ”前缀。
481+
482+
```javascript
483+
function foo() {};
484+
foo.bind({}).name // "bound foo"
485+
486+
(function(){}).bind({}).name // "bound "
481487
```
482488

483489
## 箭头函数

docs/generator.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ function log(generator) {
558558
var v;
559559
console.log('starting generator');
560560
try {
561-
g.next(); // { value: undefined, done: true } v = generator.next();
561+
v = generator.next(); // { value: undefined, done: true }
562562
console.log('第一次运行next方法', v);
563563
} catch (err) {
564564
console.log('捕捉错误', v);
@@ -587,7 +587,7 @@ log(g());
587587
// caller done
588588
```
589589
590-
上面代码一共三次运行next方法,第二次运行的时候会抛出错误,然后第三次运行的时候,Generator函数就已经结束了,不再执行下去了。
590+
上面代码一共三次运行`next`方法,第二次运行的时候会抛出错误,然后第三次运行的时候,Generator函数就已经结束了,不再执行下去了。
591591
592592
## Generator.prototype.return()
593593

docs/iterator.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ Iterator的遍历过程是这样的。
2323
下面是一个模拟next方法返回值的例子。
2424

2525
```javascript
26+
var it = makeIterator(['a', 'b']);
27+
28+
it.next() // { value: "a", done: false }
29+
it.next() // { value: "b", done: false }
30+
it.next() // { value: undefined, done: true }
31+
2632
function makeIterator(array){
2733
var nextIndex = 0;
2834
return {
@@ -33,12 +39,6 @@ function makeIterator(array){
3339
}
3440
}
3541
}
36-
37-
var it = makeIterator(['a', 'b']);
38-
39-
it.next() // { value: "a", done: false }
40-
it.next() // { value: "b", done: false }
41-
it.next() // { value: undefined, done: true }
4242
```
4343

4444
上面代码定义了一个makeIterator函数,它是一个遍历器生成函数,作用就是返回一个遍历器对象。对数组`['a', 'b']`执行这个函数,就会返回该数组的遍历器对象(即指针对象)it。
@@ -52,6 +52,13 @@ next方法返回一个对象,表示当前数据成员的信息。这个对象
5252
由于Iterator只是把接口规格加到数据结构之上,所以,遍历器与它所遍历的那个数据结构,实际上是分开的,完全可以写出没有对应数据结构的遍历器对象,或者说用遍历器对象模拟出数据结构。下面是一个无限运行的遍历器对象的例子。
5353

5454
```javascript
55+
var it = idMaker();
56+
57+
it.next().value // '0'
58+
it.next().value // '1'
59+
it.next().value // '2'
60+
// ...
61+
5562
function idMaker(){
5663
var index = 0;
5764

@@ -61,13 +68,6 @@ function idMaker(){
6168
}
6269
}
6370
}
64-
65-
var it = idMaker();
66-
67-
it.next().value // '0'
68-
it.next().value // '1'
69-
it.next().value // '2'
70-
// ...
7171
```
7272

7373
上面的例子中,遍历器生成函数idMaker,返回一个遍历器对象(即指针对象)。但是并没有对应的数据结构,或者说,遍历器对象自己描述了一个数据结构出来。
@@ -488,7 +488,7 @@ for (a of arr) {
488488
Set和Map结构也原生具有Iterator接口,可以直接使用`for...of`循环。
489489

490490
```javascript
491-
var engines = Set(["Gecko", "Trident", "Webkit", "Webkit"]);
491+
var engines = new Set(["Gecko", "Trident", "Webkit", "Webkit"]);
492492
for (var e of engines) {
493493
console.log(e);
494494
}

docs/object.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ var obj = Object.create(someOtherObj);
481481
obj.method = function() { ... }
482482
```
483483

484-
该属性没有写入ES6的正文,而是写入了附录,原因是`__proto__`前后的双引号,说明它本质上是一个内部属性,而不是一个正式的对外的API,只是由于浏览器广泛支持,才被加入了ES6。标准明确规定,只有浏览器必须部署这个属性,其他运行环境不一定需要部署,而且新的代码最好认为这个属性是不存在的。因此,无论从语义的角度,还是从兼容性的角度,都不要使用这个属性,而是使用下面的`Object.setPrototypeOf()`(写操作)、`Object.getPrototypeOf()`(读操作)、`Object.create()`(生成操作)代替。
484+
该属性没有写入ES6的正文,而是写入了附录,原因是`__proto__`前后的双下划线,说明它本质上是一个内部属性,而不是一个正式的对外的API,只是由于浏览器广泛支持,才被加入了ES6。标准明确规定,只有浏览器必须部署这个属性,其他运行环境不一定需要部署,而且新的代码最好认为这个属性是不存在的。因此,无论从语义的角度,还是从兼容性的角度,都不要使用这个属性,而是使用下面的`Object.setPrototypeOf()`(写操作)、`Object.getPrototypeOf()`(读操作)、`Object.create()`(生成操作)代替。
485485

486486
在实现上,`__proto__`调用的是`Object.prototype.__proto__`,具体实现如下。
487487

docs/proxy.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,10 @@ var twice = {
340340
apply (target, ctx, args) {
341341
return Reflect.apply(...arguments) * 2;
342342
}
343-
}
343+
};
344344
function sum (left, right) {
345345
return left + right;
346-
}
346+
};
347347
var proxy = new Proxy(sum, twice);
348348
proxy(1, 2) // 6
349349
proxy.call(null, 5, 6) // 22
@@ -370,10 +370,10 @@ var handler = {
370370
}
371371
return key in target;
372372
}
373-
}
373+
};
374374
var target = { _prop: 'foo', prop: 'foo' };
375-
'_prop' in proxy
376-
// false
375+
var proxy = new Proxy(target, handler);
376+
'_prop' in proxy // false
377377
```
378378

379379
上面代码中,如果原对象的属性名的第一个字符是下划线,`proxy.has`就会返回`false`,从而不会被`in`运算符发现。

0 commit comments

Comments
 (0)