Update article.md
Grammar suggestions
This commit is contained in:
parent
a2d32ad21e
commit
c4914ae803
1 changed files with 5 additions and 5 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
The `instanceof` operator allows to check whether an object belongs to a certain class. It also takes inheritance into account.
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
## The instanceof operator [#ref-instanceof]
|
||||
|
||||
|
@ -46,7 +46,7 @@ alert( arr instanceof Object ); // true
|
|||
|
||||
Please note that `arr` also belongs to the `Object` class. That's because `Array` prototypically inherits from `Object`.
|
||||
|
||||
Normally, `instanceof` operator examines the prototype chain for the check. We can also set a custom logic in the static method `Symbol.hasInstance`.
|
||||
Normally, `instanceof` examines the prototype chain for the check. We can also set a custom logic in the static method `Symbol.hasInstance`.
|
||||
|
||||
The algorithm of `obj instanceof Class` works roughly as follows:
|
||||
|
||||
|
@ -68,7 +68,7 @@ The algorithm of `obj instanceof Class` works roughly as follows:
|
|||
alert(obj instanceof Animal); // true: Animal[Symbol.hasInstance](obj) is called
|
||||
```
|
||||
|
||||
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.
|
||||
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 any prototype in the `obj` prototype chain.
|
||||
|
||||
In other words, compare one after another:
|
||||
```js
|
||||
|
@ -107,7 +107,7 @@ By the way, there's also a method [objA.isPrototypeOf(objB)](mdn:js/object/isPro
|
|||
|
||||
It's funny, but the `Class` constructor itself does not participate in the check! Only the chain of prototypes and `Class.prototype` matters.
|
||||
|
||||
That can lead to interesting consequences when `prototype` property is changed after the object is created.
|
||||
That can lead to interesting consequences when a `prototype` property is changed after the object is created.
|
||||
|
||||
Like here:
|
||||
|
||||
|
@ -186,7 +186,7 @@ let user = {
|
|||
alert( {}.toString.call(user) ); // [object User]
|
||||
```
|
||||
|
||||
For most environment-specific objects, there is such a property. Here are few browser specific examples:
|
||||
For most environment-specific objects, there is such a property. Here are some browser specific examples:
|
||||
|
||||
```js run
|
||||
// toStringTag for the environment-specific object and class:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue