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

【 手写系列 】实现New操作符 #31

Open
yang1212 opened this issue Feb 26, 2022 · 0 comments
Open

【 手写系列 】实现New操作符 #31

yang1212 opened this issue Feb 26, 2022 · 0 comments
Labels

Comments

@yang1212
Copy link
Owner

yang1212 commented Feb 26, 2022

关于New

function createNew(fn, ...arg) {
  let obj = Object.create(fn.prototype)
  let result = fn.apply(obj, arg)
  return obj instanceof Object ? obj : result
}

new 构建函数 --》 返回实例 --》实例可访问原型对象

@yang1212 yang1212 added the JS label Feb 26, 2022
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