diff --git a/1-js/07-object-oriented-programming/08-class-patterns/1-inheritance-error-assign/solution.md b/1-js/07-object-oriented-programming/08-class-patterns/1-inheritance-error-assign/solution.md index 55f945ca5d..6f062e3984 100644 --- a/1-js/07-object-oriented-programming/08-class-patterns/1-inheritance-error-assign/solution.md +++ b/1-js/07-object-oriented-programming/08-class-patterns/1-inheritance-error-assign/solution.md @@ -1,12 +1,12 @@ -Here's the line with the error: +这里有一行报错代码: ```js Rabbit.prototype = Animal.prototype; ``` -Here `Rabbit.prototype` and `Animal.prototype` become the same object. So methods of both classes become mixed in that object. +这里 `Rabbit.prototype` 和 `Animal.prototype` 变成了同样的对象。所以这两个类的方法都混合在了这个对象中。 -As a result, `Rabbit.prototype.walk` overwrites `Animal.prototype.walk`, so all animals start to bounce: +结果, `Rabbit.prototype.walk` 重写了 `Animal.prototype.walk`,所以所有动物都开始跳: ```js run function Animal(name) { @@ -35,7 +35,7 @@ animal.walk(); // pig bounces! */!* ``` -The correct variant would be: +正确的变体是: ```js Rabbit.prototype.__proto__ = Animal.prototype; @@ -43,4 +43,4 @@ Rabbit.prototype.__proto__ = Animal.prototype; Rabbit.prototype = Object.create(Animal.prototype); ``` -That makes prototypes separate, each of them stores methods of the corresponding class, but `Rabbit.prototype` inherits from `Animal.prototype`. +这使原型分开,每个原型都存储相应类的方法,但是 `Rabbit.prototype` 继承自 `Animal.prototype`。