You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/09-classes/06-instanceof/article.md
+5-5
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
The `instanceof` operator allows to check whether an object belongs to a certain class. It also takes inheritance into account.
4
4
5
-
Such a check may be necessary in many cases, here we'll use it for building a *polymorphic* function, the one that treats arguments differently depending on their type.
5
+
Such a check may be necessary in many cases. Here we'll use it for building a *polymorphic* function, the one that treats arguments differently depending on their type.
Please note that `arr` also belongs to the `Object` class. That's because `Array` prototypically inherits from `Object`.
48
48
49
-
Normally, `instanceof`operator examines the prototype chain for the check. We can also set a custom logic in the static method `Symbol.hasInstance`.
49
+
Normally, `instanceof` examines the prototype chain for the check. We can also set a custom logic in the static method `Symbol.hasInstance`.
50
50
51
51
The algorithm of `obj instanceof Class` works roughly as follows:
52
52
@@ -68,7 +68,7 @@ The algorithm of `obj instanceof Class` works roughly as follows:
68
68
alert(obj instanceof Animal); // true: Animal[Symbol.hasInstance](obj) is called
69
69
```
70
70
71
-
2. Most classes do not have `Symbol.hasInstance`. In that case, the standard logic is used:`obj instanceOf Class` checks whether `Class.prototype`equals to one of prototypes in the `obj` prototype chain.
71
+
2. Most classes do not have `Symbol.hasInstance`. In that case, the standard logic is used:`obj instanceOf Class` checks whether `Class.prototype`is equal to one of the prototypes in the `obj` prototype chain.
72
72
73
73
In other words, compare one after another:
74
74
```js
@@ -107,7 +107,7 @@ By the way, there's also a method [objA.isPrototypeOf(objB)](mdn:js/object/isPro
107
107
108
108
It's funny, but the `Class` constructor itself does not participate in the check! Only the chain of prototypes and `Class.prototype` matters.
109
109
110
-
That can lead to interesting consequences when `prototype` property is changed after the object is created.
110
+
That can lead to interesting consequences when a `prototype` property is changed after the object is created.
111
111
112
112
Like here:
113
113
@@ -186,7 +186,7 @@ let user = {
186
186
alert( {}.toString.call(user) ); // [object User]
187
187
```
188
188
189
-
For most environment-specific objects, there is such a property. Here are few browser specific examples:
189
+
For most environment-specific objects, there is such a property. Here are some browser specific examples:
190
190
191
191
```js run
192
192
// toStringTag for the environment-specific object and class:
0 commit comments