Skip to content

Commit f2b46f5

Browse files
committed
Translate Borrowing part
1 parent 38a3e66 commit f2b46f5

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,17 @@ alert( "La".repeat(3) ); // LaLaLa
153153
```
154154

155155

156-
## Borrowing from prototypes
156+
## Одалживание у прототипов
157157

158-
In the chapter <info:call-apply-decorators#method-borrowing> we talked about method borrowing.
158+
В главе <info:call-apply-decorators#method-borrowing> мы говорили об одалживании методов.
159159

160-
That's when we take a method from one object and copy it into another.
160+
Это когда мы берем метод из одного объекта и копируем его в другой.
161161

162-
Some methods of native prototypes are often borrowed.
162+
Некоторые методы встроенных прототипов часто можно одолжить.
163163

164-
For instance, if we're making an array-like object, we may want to copy some array methods to it.
164+
Например, если мы создаем объект похожий на массив, мы возможно захотим скопировать некоторые методы массива в этот объект.
165165

166-
E.g.
166+
Пример:
167167

168168
```js run
169169
let obj = {
@@ -179,13 +179,13 @@ obj.join = Array.prototype.join;
179179
alert( obj.join(',') ); // Hello,world!
180180
```
181181

182-
It works, because the internal algorithm of the built-in `join` method only cares about the correct indexes and the `length` property, it doesn't check that the object is indeed the array. And many built-in methods are like that.
182+
Это работает, потому что для внутреннего алгоритма встроенного метода `join` важна только корректность индексов и свойства `length`, он не проверяет является ли объект на самом деле массивом. И многие встроенные методы работают так же.
183183

184-
Another possibility is to inherit by setting `obj.__proto__` to `Array.prototype`, so all `Array` methods are automatically available in `obj`.
184+
!! Другая возможность -- наследование, установив `obj.__proto__` как `Array.prototype`, таким образом все методы `Array` станут автоматически доступны в `obj`.
185185

186-
But that's impossible if `obj` already inherits from another object. Remember, we only can inherit from one object at a time.
186+
Но это будет невозможно, если `obj` уже наследуется от другого объекта. Помните, мы можем наследоваться только от одного объекта одновременно.
187187

188-
Borrowing methods is flexible, it allows to mix functionality from different objects if needed.
188+
Одалживание методов гибкий способ, он позволяет смешивать функциональность разных объектов по необходимости.
189189

190190
## Summary
191191

0 commit comments

Comments
 (0)