Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

instanceof模拟 #4

Open
shen-zhao opened this issue Apr 20, 2021 · 0 comments
Open

instanceof模拟 #4

shen-zhao opened this issue Apr 20, 2021 · 0 comments
Labels

Comments

@shen-zhao
Copy link
Owner

shen-zhao commented Apr 20, 2021

instanceof MDN

// instanceof 运算符用于检测构造函数的 prototype 属性是否出现在某个实例对象的原型链上。

function instanceofFn(left, right) {
  var target = right.prototype
  while (left) {
    left = left.__proto__
    if (target === left) {
    	return true
    }
  }
    
  return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant