mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2025-05-28 21:32:20 +00:00
commit
b5a1e6c72a
@ -447,7 +447,7 @@ B.__proto__ = A;
|
|||||||
这两条继承链,可以这样理解:作为一个对象,子类(`B`)的原型(`__proto__`属性)是父类(`A`);作为一个构造函数,子类(`B`)的原型对象(`prototype`属性)是父类的原型对象(`prototype`属性)的实例。
|
这两条继承链,可以这样理解:作为一个对象,子类(`B`)的原型(`__proto__`属性)是父类(`A`);作为一个构造函数,子类(`B`)的原型对象(`prototype`属性)是父类的原型对象(`prototype`属性)的实例。
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
Object.create(A.prototype);
|
B.prototype = Object.create(A.prototype);
|
||||||
// 等同于
|
// 等同于
|
||||||
B.prototype.__proto__ = A.prototype;
|
B.prototype.__proto__ = A.prototype;
|
||||||
```
|
```
|
||||||
|
@ -256,7 +256,7 @@ var myObject = {
|
|||||||
Reflect.has(myObject, 'foo') // true
|
Reflect.has(myObject, 'foo') // true
|
||||||
```
|
```
|
||||||
|
|
||||||
如果第一个参数不是对象,`Reflect.has`方法会报错。
|
如果`Reflect.has()`方法的第一个参数不是对象,会报错。
|
||||||
|
|
||||||
### Reflect.deleteProperty(obj, name)
|
### Reflect.deleteProperty(obj, name)
|
||||||
|
|
||||||
@ -273,7 +273,8 @@ Reflect.deleteProperty(myObj, 'foo');
|
|||||||
```
|
```
|
||||||
|
|
||||||
该方法返回一个布尔值。如果删除成功,或者被删除的属性不存在,返回`true`;删除失败,被删除的属性依然存在,返回`false`。
|
该方法返回一个布尔值。如果删除成功,或者被删除的属性不存在,返回`true`;删除失败,被删除的属性依然存在,返回`false`。
|
||||||
如果第一个参数不是对象,`Reflect.deleteProperty`方法会报错。
|
|
||||||
|
如果`Reflect.deleteProperty()`方法的第一个参数不是对象,会报错。
|
||||||
|
|
||||||
### Reflect.construct(target, args)
|
### Reflect.construct(target, args)
|
||||||
|
|
||||||
@ -291,7 +292,7 @@ const instance = new Greeting('张三');
|
|||||||
const instance = Reflect.construct(Greeting, ['张三']);
|
const instance = Reflect.construct(Greeting, ['张三']);
|
||||||
```
|
```
|
||||||
|
|
||||||
如果第一个参数不是函数,`Reflect.construct`方法会报错。
|
如果`Reflect.construct()`方法的第一个参数不是函数,会报错。
|
||||||
|
|
||||||
### Reflect.getPrototypeOf(obj)
|
### Reflect.getPrototypeOf(obj)
|
||||||
|
|
||||||
@ -511,7 +512,7 @@ Reflect.ownKeys(myObject)
|
|||||||
// ['foo', 'bar', Symbol(baz), Symbol(bing)]
|
// ['foo', 'bar', Symbol(baz), Symbol(bing)]
|
||||||
```
|
```
|
||||||
|
|
||||||
如果第一个参数不是对象,`Reflect.ownKeys`方法会报错。
|
如果`Reflect.ownKeys()`方法的第一个参数不是对象,会报错。
|
||||||
|
|
||||||
## 实例:使用 Proxy 实现观察者模式
|
## 实例:使用 Proxy 实现观察者模式
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ const sym = Symbol('foo');
|
|||||||
const sym = Symbol('foo');
|
const sym = Symbol('foo');
|
||||||
|
|
||||||
String(sym) // "Symbol(foo)"
|
String(sym) // "Symbol(foo)"
|
||||||
sym.toString // "Symbol(foo)"
|
sym.toString() // "Symbol(foo)"
|
||||||
```
|
```
|
||||||
|
|
||||||
上面的用法不是很方便。[ES2019](https://github.com/tc39/proposal-Symbol-description) 提供了一个实例属性`description`,直接返回 Symbol 的描述。
|
上面的用法不是很方便。[ES2019](https://github.com/tc39/proposal-Symbol-description) 提供了一个实例属性`description`,直接返回 Symbol 的描述。
|
||||||
|
Loading…
x
Reference in New Issue
Block a user