instanceof原理

kingcwt2022-11-28前端javascript
const myInstanceof = (target,obj) =>{
  let t = target;
  while(t){
    if(t === obj.prototype){
      return true;
    }
    t = t.__proto__;
  }
  return false;
}

console.log(myInstanceof([1,2,3],Array))
Last Updated 10/16/2023, 7:06:22 AM
What do you think?
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0
Comments
  • Latest
  • Oldest
  • Hottest
Powered by Waline v2.15.8