Skip to content

Commit abaab57

Browse files
authored
Update article.md
1 parent 1f9ae74 commit abaab57

File tree

1 file changed

+10
-10
lines changed
  • 1-js/07-object-oriented-programming/11-instanceof

1 file changed

+10
-10
lines changed

1-js/07-object-oriented-programming/11-instanceof/article.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ The algorithm of `obj instanceof Class` works roughly as follows:
7070

7171
In other words, compare:
7272
```js
73-
obj.__proto__ == Class.prototype
74-
obj.__proto__.__proto__ == Class.prototype
75-
obj.__proto__.__proto__.__proto__ == Class.prototype
73+
obj.__proto__ === Class.prototype
74+
obj.__proto__.__proto__ === Class.prototype
75+
obj.__proto__.__proto__.__proto__ === Class.prototype
7676
...
7777
```
7878

79-
In the example above `Rabbit.prototype == rabbit.__proto__`, so that gives the answer immediately.
79+
In the example above `Rabbit.prototype === rabbit.__proto__`, so that gives the answer immediately.
8080

8181
In the case of an inheritance, `rabbit` is an instance of the parent class as well:
8282

@@ -88,8 +88,8 @@ The algorithm of `obj instanceof Class` works roughly as follows:
8888
*!*
8989
alert(rabbit instanceof Animal); // true
9090
*/!*
91-
// rabbit.__proto__ == Rabbit.prototype
92-
// rabbit.__proto__.__proto__ == Animal.prototype (match!)
91+
// rabbit.__proto__ === Rabbit.prototype
92+
// rabbit.__proto__.__proto__ === Animal.prototype (match!)
9393
```
9494

9595
Here's the illustration of what `rabbit instanceof Animal` compares with `Animal.prototype`:
@@ -117,7 +117,7 @@ alert( rabbit instanceof Rabbit ); // false
117117
*/!*
118118
```
119119
120-
That's one of reasons to avoid changing `prototype`. Just to keep safe.
120+
That's one of the reasons to avoid changing `prototype`. Just to keep safe.
121121

122122
## Bonus: Object toString for the type
123123

@@ -130,9 +130,9 @@ alert(obj); // [object Object]
130130
alert(obj.toString()); // the same
131131
```
132132

133-
That's their implementation of `toString`. But there's a hidden feature thank makes `toString` actually much more powerful than that. We can use it as an extended `typeof` and an alternative for `instanceof`.
133+
That's their implementation of `toString`. But there's a hidden feature that makes `toString` actually much more powerful than that. We can use it as an extended `typeof` and an alternative for `instanceof`.
134134

135-
Sounds strange? Indeed. Let's demistify.
135+
Sounds strange? Indeed. Let's demystify.
136136
137137
By [specification](https://tc39.github.io/ecma262/#sec-object.prototype.tostring), the built-in `toString` can be extracted from the object and executed in the context of any other value. And its result depends on that value.
138138
@@ -175,7 +175,7 @@ For instance:
175175

176176
```js run
177177
let user = {
178-
[Symbol.toStringTag]: 'User'
178+
[Symbol.toStringTag]: "User"
179179
};
180180

181181
alert( {}.toString.call(user) ); // [object User]

0 commit comments

Comments
 (0)