// Analysis: if A can find b. prototype along the prototype chain, then instanceof B is true
// If b. prototype is found, return true, otherwise return false

const instanceOf = (A, B) = > {
  let p = A
  while (p) {
    if (p === B.prototype) {
      return true
    }
    p = p.__proto__
  }
  return false
}



// Simple test
var foo = {}, F = function () {}Object.prototype.a = 'value a'
Function.prototype.b = 'value b'

console.log(foo.a) // value a
console.log(foo.b) // undefinded

console.log(F.a)  // value a
console.log(F.b) // value a
Copy the code