[js] instanceof和原型链

boomwu

关注

阅读 107

2022-12-21


object instanceof constructor

参数

object

  • 要检测的对象.

constructor

  • 某个构造函数

描述

instanceof 运算符用来检测 constructor.prototype 是否存在于参数 object 的原型链上。

// 定义构造函数
function C(){}


// true,因为 Object.getPrototypeOf(o) === C.prototype
o instanceof C;

​​instanceof 和原型链​​


精彩评论(0)

0 0 举报