Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Правки форматирования и перевод фраз в 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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
s0nought wants to merge1 commit intojavascript-tutorial:master
base:master
Choose a base branch
Loading
froms0nought:patch-10
Open
Changes fromall 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 deletions1-js/08-prototypes/01-prototype-inheritance/article.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,7 +71,7 @@ let animal = {
eats: true,
*!*
walk() {
alert("Animal walk");
alert("Животное идёт");
}
*/!*
};
Expand All@@ -83,7 +83,7 @@ let rabbit = {

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

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

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

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

Expand DownExpand Up@@ -165,11 +165,11 @@ let rabbit = {

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

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

Теперь вызов `rabbit.walk()` находит метод непосредственно в объекте и выполняет его, не используя прототип:
Expand DownExpand Up@@ -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
```
Expand DownExpand Up@@ -230,7 +234,7 @@ alert(admin.surname); // Cooper
let animal = {
walk() {
if (!this.isSleeping) {
alert(`I walk`);
alert('Я иду');
}
},
sleep() {
Expand All@@ -239,7 +243,7 @@ let animal = {
};

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

Expand DownExpand Up@@ -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
*/!*
```

Expand All@@ -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
}
}
```
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp