Skip to content

Latest commit

 

History

History
16 lines (13 loc) · 314 Bytes

手写instanceof.md

File metadata and controls

16 lines (13 loc) · 314 Bytes

手写instanceof

function myInstanceof(left, right) {
  var prototype = right.prototype
  left = left.__proto__
  
  while(true) {
    if (left === null || left === undefined) return false
    if (left === prototype) return true
    
    left = left.__proto__  
  }
}
myInstanceof({}, Object)