instanceof

# instanceof

// instanceof运算符
// 定义:判断对象是否属于某个构造函数的实例
// 原理:判断构造函数的原型对象是否出现在对象的原型链上
module.exports = function customINstanceof (ins, constructor) {
 const proto = Object.getPrototypeOf(ins)

 if (proto === constructor.prototype) return true
 if (!proto) return false

 return customINstanceof(proto, constructor)
}
1
2
3
4
5
6
7
8
9
10
11
上次更新: 2022/7/25 下午12:50:39