ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

实现 instanceof 操作符

实现 instanceof 操作符
// 实现 instanceof 操作符
function myInstanceof(left, right) {// 实现if(typeof right!=='function' || right.constructor===null){throw new Error('right must be function');}if(left===null || typeof left!=='object' && typeof left!=='function'){return false;}let leftProto =Object.getPrototypeOf(left);while(true){if(leftProto===null){return false;}if(leftProto===right.prototype){return true;}leftProto=Object.getPrototypeOf(leftProto);}
}

 

返回列表