![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
手写JS系列
AndyPoplar
学无止境
展开
-
手写instanceof原理
A instanceof B 判断 B 的 prototype 属性指向的原型对象(B.prototype)是否在对象 A 的原型链上。 如果在,则为 true;如果不在,则为 false。 function myInstanceof(left, right) { if (typeof left !== "object" || left == null) return false let proto = Object.getPrototypeOf(left); while (true) {原创 2020-05-28 15:32:23 · 345 阅读 · 0 评论 -
手写new实现原理
function modelNew(Parent, ...test) { // 1.创建一个空对象 let result = {}; // 2.把Parent的this指向this result.__proto__ = Parent.prototype; // 3.执行parent的代码为result添加属性,如果构造函数有返回结果,则接收 let target = Parent.apply(result, test) if (typeof target === "ob原创 2020-05-28 14:28:38 · 599 阅读 · 0 评论