mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2025-05-25 03:02:21 +00:00
docs(class-extends): 子类继承父类的静态方法
This commit is contained in:
parent
70efc5d7d6
commit
911dd3404a
@ -92,6 +92,23 @@ cp instanceof Point // true
|
|||||||
|
|
||||||
上面代码中,实例对象`cp`同时是`ColorPoint`和`Point`两个类的实例,这与 ES5 的行为完全一致。
|
上面代码中,实例对象`cp`同时是`ColorPoint`和`Point`两个类的实例,这与 ES5 的行为完全一致。
|
||||||
|
|
||||||
|
最后,父类的静态方法,也会被子类继承。
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
class A {
|
||||||
|
static hello() {
|
||||||
|
console.log('hello world');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class B extends A {
|
||||||
|
}
|
||||||
|
|
||||||
|
B.hello() // hello world
|
||||||
|
```
|
||||||
|
|
||||||
|
上面代码中,`hello()`是`A`类的静态方法,`B`继承`A`,也继承了`A`的静态方法。
|
||||||
|
|
||||||
## Object.getPrototypeOf()
|
## Object.getPrototypeOf()
|
||||||
|
|
||||||
`Object.getPrototypeOf`方法可以用来从子类上获取父类。
|
`Object.getPrototypeOf`方法可以用来从子类上获取父类。
|
||||||
|
Loading…
x
Reference in New Issue
Block a user