Skip to content

Commit 876498f

Browse files
committed
types/instanceof
1 parent 2d6c991 commit 876498f

1 file changed

Lines changed: 9 additions & 15 deletions

File tree

‎doc/ru/types/instanceof.md‎

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
## The `instanceof` operator
1+
## Оператор `instanceof`
22

3-
The `instanceof` operator compares the constructors of its two operands. It is
4-
only useful when comparing custom made objects. Used on built-in types, it is
5-
nearly as useless as the [typeof operator](#types.typeof).
3+
Оператор `instanceof` сравнивает конструкторы двух операндов. Это полезно только когда сравниваются пользовательские объекты. Использование на встроенных типах почти так же бесполезно, как оператор [оператор typeof](#types.typeof).
64

7-
### Comparing custom objects
5+
### Сравнение пользовательских объектов
86

97
function Foo() {}
108
function Bar() {}
@@ -13,26 +11,22 @@ nearly as useless as the [typeof operator](#types.typeof).
1311
new Bar() instanceof Bar; // true
1412
new Bar() instanceof Foo; // true
1513

16-
// This just sets Bar.prototype to the function object Foo
17-
// But not to an actual instance of Foo
14+
// Всего лишь присваиваем Bar.prototype объект функции Foo,
15+
// но не экземпляра Foo
1816
Bar.prototype = Foo;
1917
new Bar() instanceof Foo; // false
2018

21-
### Using `instanceof` with native types
19+
### Использование `instanceof` со встроенными типами
2220

2321
new String('foo') instanceof String; // true
2422
new String('foo') instanceof Object; // true
2523

2624
'foo' instanceof String; // false
2725
'foo' instanceof Object; // false
2826

29-
One important thing to note here is, that `instanceof` does not work on objects
30-
that origin from different JavaScript contexts (e.g. different documents
31-
in a web browser), since their constructors will not be the exact same object.
27+
Здесь надо отметить одну важную вещь: `instanceof` не работает на объектах, которые происходят из разных контекстов JavaScript (например, из различных документы в web-браузере), так как их конструкторы не будут конструкторами *тех самых* объектов.
3228

33-
### In conclusion
29+
### Заключение
3430

35-
The `instanceof` operator should **only** be used when dealing with custom made
36-
objects that origin from the same JavaScript context. Just like the
37-
[`typeof`](#types.typeof) operator, every other use of it should be **avoided**.
31+
Оператор instanceof должен использоваться **только** при обращении к пользовательским объектам, происходящим из одного контекста JavaScript. Так же, как и в случае оператора `typeof`, любое другое использование необходимо **избегать**.
3832

0 commit comments

Comments
 (0)