File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -262,15 +262,15 @@ v instanceof Vehicle // true
262
262
263
263
上面代码中,对象` v ` 是构造函数` Vehicle ` 的实例,所以返回` true ` 。
264
264
265
- ` instanceof ` 运算符的左边是实例对象,右边是构造函数。它会检查右边构建函数的原型对象 (prototype),是否在左边对象的原型链上。因此,下面两种写法是等价的。
265
+ ` instanceof ` 运算符的左边是实例对象,右边是构造函数。它会检查右边构造函数的原型对象 (prototype),是否在左边对象的原型链上。因此,下面两种写法是等价的。
266
266
267
267
``` javascript
268
268
v instanceof Vehicle
269
269
// 等同于
270
270
Vehicle .prototype .isPrototypeOf (v)
271
271
```
272
272
273
- 上面代码中,` Object.prototype. isPrototypeOf ` 的详细解释见后文 。
273
+ 上面代码中,` Object ` 是对象的构造函数,它的原型对象是 ` Object .prototype` , ` isPrototypeOf() ` 方法用于检查某个对象是否为另一个对象的原型,详细解释见后文 。
274
274
275
275
由于` instanceof ` 检查整个原型链,因此同一个实例对象,可能会对多个构造函数都返回` true ` 。
276
276
@@ -298,10 +298,10 @@ null instanceof Object // false
298
298
``` javascript
299
299
var obj = Object .create (null );
300
300
typeof obj // "object"
301
- Object . create ( null ) instanceof Object // false
301
+ obj instanceof Object // false
302
302
```
303
303
304
- 上面代码中,` Object.create(null) ` 返回一个新对象` obj ` ,它的原型是` null ` (` Object.create ` 的详细介绍见后文)。右边的构造函数` Object ` 的` prototype ` 属性,不在左边的原型链上,因此` instanceof ` 就认为` obj ` 不是` Object ` 的实例。但是,只要一个对象的原型不是 ` null ` , ` instanceof ` 运算符的判断就不会失真 。
304
+ 上面代码中,` Object.create(null) ` 返回一个新对象` obj ` ,它的原型是` null ` (` Object.create() ` 的详细介绍见后文)。右边的构造函数` Object ` 的` prototype ` 属性,不在左边的原型链上,因此` instanceof ` 就认为` obj ` 不是` Object ` 的实例。这是唯一的 ` instanceof ` 运算符判断会失真的情况(一个对象的原型是 ` null ` ) 。
305
305
306
306
` instanceof ` 运算符的一个用处,是判断值的类型。
307
307
You can’t perform that action at this time.
0 commit comments