手写instanceof,判断对象之间关联性
function instance_of(L,R){ const baseType = ['string','number','boolean','undefined','null','symbol']; if(baseType.includes(typeof L)) { return false } let RP = R.prototype; let Lp = L.__proto__; while(true){ if(Lp === null){ return false; } if(Lp === RP){ return true; } Lp = Lp.__proto__; } } function person(name){ this.name = name; } var children = new person('小孩'); console.log(instance_of(children,person)); //true console.log(children instanceof person); //true
前端问题总结 文章被收录于专栏
总结一些前端常见的面试笔试题,来和大家分享鸭