Skip to content

Правки форматирования и перевод фраз в 8.1 #1973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions 1-js/08-prototypes/01-prototype-inheritance/article.md
Original file line number Diff line number Diff line change
@@ -71,7 +71,7 @@ let animal = {
eats: true,
*!*
walk() {
alert("Animal walk");
alert("Животное идёт");
}
*/!*
};
@@ -83,7 +83,7 @@ let rabbit = {

// walk взят из прототипа
*!*
rabbit.walk(); // Animal walk
rabbit.walk(); // Животное идёт
*/!*
```

@@ -97,7 +97,7 @@ rabbit.walk(); // Animal walk
let animal = {
eats: true,
walk() {
alert("Animal walk");
alert("Животное идёт");
}
};

@@ -116,7 +116,7 @@ let longEar = {
};

// walk взят из цепочки прототипов
longEar.walk(); // Animal walk
longEar.walk(); // Животное идёт
alert(longEar.jumps); // true (из rabbit)
```

@@ -165,11 +165,11 @@ let rabbit = {

*!*
rabbit.walk = function() {
alert("Rabbit! Bounce-bounce!");
alert("Кролик! Прыг-скок!");
};
*/!*

rabbit.walk(); // Rabbit! Bounce-bounce!
rabbit.walk(); // Кролик! Прыг-скок!
```

Теперь вызов `rabbit.walk()` находит метод непосредственно в объекте и выполняет его, не используя прототип:
@@ -199,10 +199,14 @@ let admin = {
isAdmin: true
};

*!*
alert(admin.fullName); // John Smith (*)
*/!*

// срабатывает сеттер!
*!*
admin.fullName = "Alice Cooper"; // (**)
*/!*
alert(admin.name); // Alice
alert(admin.surname); // Cooper
```
@@ -230,7 +234,7 @@ alert(admin.surname); // Cooper
let animal = {
walk() {
if (!this.isSleeping) {
alert(`I walk`);
alert('Я иду');
}
},
sleep() {
@@ -239,7 +243,7 @@ let animal = {
};

let rabbit = {
name: "White Rabbit",
name: "Белый кролик",
__proto__: animal
};

@@ -276,12 +280,12 @@ let rabbit = {

*!*
// Object.keys возвращает только собственные ключи
alert(Object.keys(rabbit)); // jumps
alert( Object.keys(rabbit) ); // jumps
*/!*

*!*
// for..in проходит и по своим, и по унаследованным ключам
for(let prop in rabbit) alert(prop); // jumps, затем eats
for (let prop in rabbit) alert(prop); // jumps, затем eats
*/!*
```

@@ -299,13 +303,13 @@ let rabbit = {
__proto__: animal
};

for(let prop in rabbit) {
for (let prop in rabbit) {
let isOwn = rabbit.hasOwnProperty(prop);

if (isOwn) {
alert(`Our: ${prop}`); // Our: jumps
alert(`Собственное: ${prop}`); // Собственное: jumps
} else {
alert(`Inherited: ${prop}`); // Inherited: eats
alert(`Унаследованное: ${prop}`); // Унаследованное: eats
}
}
```