Skip to content

Commit 38a3e66

Browse files
committed
Translate Changing native prototypes part
1 parent 5f2549c commit 38a3e66

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

1-js/08-prototypes/03-native-prototypes/article.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Нативные прототипы
1+
# Встроенные прототипы
22

33
Свойство `"prototype"` широко используется в самом ядре JavaScript. Все встроенные функции-конструкторы используют его.
44

@@ -107,9 +107,9 @@ alert(f.__proto__.__proto__ == Object.prototype); // true, наследует о
107107
Специальные значения `null` и `undefined` стоят особняком. У них нет, объектов-оберток, так что методы и свойства им недоступны. Также у них нет соответствующих прототипов.
108108
```
109109
110-
## Changing native prototypes [#native-prototype-change]
110+
## Изменение встроенных прототипов [#native-prototype-change]
111111
112-
Native prototypes can be modified. For instance, if we add a method to `String.prototype`, it becomes available to all strings:
112+
Встроенные прототипы можно изменять. Например, если добавить метод к `String.prototype`, метод становится доступен для все строк:
113113
114114
```js run
115115
String.prototype.show = function() {
@@ -119,32 +119,32 @@ String.prototype.show = function() {
119119
"BOOM!".show(); // BOOM!
120120
```
121121

122-
During the process of development, we may have ideas for new built-in methods we'd like to have, and we may be tempted to add them to native prototypes. But that is generally a bad idea.
122+
В течение процесса разработки, у нас могут быть идеи о новых встроенных методах, которые нам хотелось бы иметь, и можем испытать искушение добавить их во встроенные прототипы. Но в целом, это плохая идея.
123123

124124
```warn
125-
Prototypes are global, so it's easy to get a conflict. If two libraries add a method `String.prototype.show`, then one of them will be overwriting the other.
125+
Прототипы глобальны, и очень легко получить конфликты. Если две библиотеки добавляют методы `String.prototype.show`, то одна из них перепишет другой.
126126
127-
So, generally, modifying a native prototype is considered a bad idea.
127+
Так что, в целом, изменение встроенных прототипов считается плохой идей.
128128
```
129129

130-
**In modern programming, there is only one case where modifying native prototypes is approved. That's polyfilling.**
130+
**В современном программировании есть только один случай, в котором одобряется изменение встроенных прототипов. Это создание полифилов.
131131

132-
Polyfilling is a term for making a substitute for a method that exists in JavaScript specification, but not yet supported by current JavaScript engine.
132+
Полифил - это термин, который означает замену метода, существуего в спецификации JavaScript, но еще не поддерживается текущим движком JavaScript.
133133

134-
Then we may implement it manually and populate the built-in prototype with it.
134+
Тогда мы можем реализовать его сами и добавить его во встроенный прототип.
135135

136-
For instance:
136+
Например:
137137

138138
```js run
139-
if (!String.prototype.repeat) { // if there's no such method
140-
// add it to the prototype
139+
if (!String.prototype.repeat) { // Если такого метода нет
140+
// добавляем его в прототип
141141

142142
String.prototype.repeat = function(n) {
143-
// repeat the string n times
143+
// повторить строку n раз
144144

145-
// actually, the code should be a little bit more complex than that
146-
// (the full algorithm is in the specification)
147-
// but even an imperfect polyfill is often considered good enough
145+
// на самом деле код должен быть немного более сложным
146+
// (полный алгоритм можно найти в спецификации)
147+
// но даже неполный полифил часто считается достаточно хорошим
148148
return new Array(n + 1).join(this);
149149
};
150150
}

0 commit comments

Comments
 (0)