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

day3 #3

Open
elegantYU opened this issue Mar 26, 2021 · 2 comments
Open

day3 #3

elegantYU opened this issue Mar 26, 2021 · 2 comments

Comments

@elegantYU
Copy link
Owner

知识点

@elegantYU
Copy link
Owner Author

实现call

Function.prototype.call2 = function (ctx) {
  var ctx = ctx || window
  ctx.fn = this

  var args = [] // 参数
  for (var i = 1, len = arguments.length; i < len; i++) {
    args.push('arguments['+  i +']')
  }
  var result = eval('ctx.fn('+ args +')')

  delete ctx.fn
  return result
}

@elegantYU
Copy link
Owner Author

instanceof 原理

  • instanceof左侧 left的proto与右侧right的prototype比较是否相等
  • 若不相等,查找left.proto__的上层__proto,继续比较
  • 返回结果

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant