closes #1589
This commit is contained in:
parent
2063dbddd7
commit
29c4fc680e
1 changed files with 6 additions and 3 deletions
|
@ -123,14 +123,15 @@ That is the same as a direct assignment to `Article`:
|
||||||
Article.publisher = "Ilya Kantor";
|
Article.publisher = "Ilya Kantor";
|
||||||
```
|
```
|
||||||
|
|
||||||
## Inheritance of static methods
|
## Inheritance of static properties and methods
|
||||||
|
|
||||||
Static methods are inherited.
|
Static properties and methods are inherited.
|
||||||
|
|
||||||
For instance, `Animal.compare` in the code below is inherited and accessible as `Rabbit.compare`:
|
For instance, `Animal.compare` and `Animal.planet` in the code below are inherited and accessible as `Rabbit.compare` and `Rabbit.planet`:
|
||||||
|
|
||||||
```js run
|
```js run
|
||||||
class Animal {
|
class Animal {
|
||||||
|
static planet = "Earth";
|
||||||
|
|
||||||
constructor(name, speed) {
|
constructor(name, speed) {
|
||||||
this.speed = speed;
|
this.speed = speed;
|
||||||
|
@ -167,6 +168,8 @@ rabbits.sort(Rabbit.compare);
|
||||||
*/!*
|
*/!*
|
||||||
|
|
||||||
rabbits[0].run(); // Black Rabbit runs with speed 5.
|
rabbits[0].run(); // Black Rabbit runs with speed 5.
|
||||||
|
|
||||||
|
alert(Rabbit.planet); // Earth
|
||||||
```
|
```
|
||||||
|
|
||||||
Now when we call `Rabbit.compare`, the inherited `Animal.compare` will be called.
|
Now when we call `Rabbit.compare`, the inherited `Animal.compare` will be called.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue