javascript之instanceof

mac2022-06-30  23

定义和用法

instanceof 运算符用来检测 constructor.prototype 是否存在于参数 object 的原型链上。 语法: object instanceof constructor object要检测的对象.constructor某个构造函数

实现 instanceof

function instanceof(left, right) { // 获得类型的原型 let prototype = right.prototype // 获得对象的原型 left = left.__proto__ // 判断对象的类型是否等于类型的原型 while (true) { if (left === null) return false if (prototype === left) return true left = left.__proto__ } }

转载于:https://www.cnblogs.com/guangzan/p/11270642.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)