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

JavaScript模拟实现Object.assign #100

Open
GGXXMM opened this issue May 2, 2021 · 0 comments
Open

JavaScript模拟实现Object.assign #100

GGXXMM opened this issue May 2, 2021 · 0 comments
Labels
⭐️ js js knowledge

Comments

@GGXXMM
Copy link
Owner

GGXXMM commented May 2, 2021

/**
 * 手写Object.assign:浅拷贝对象
 * @param {*} target 目标对象
 * @param {*} source 源对象
 * @return {*} 
 */
function assign(target, source) {
  if(target == null) {
    throw new TypeError('Cannot convert undefined or null to object')
  }
  let ret = Object(target);// 包装成对象
  for(var key in source) {
    if(source.hasOwnProperty(key)){
      ret[key] = source[key]
    }
  }
  return ret;
}
@GGXXMM GGXXMM added the ⭐️ js js knowledge label Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⭐️ js js knowledge
Projects
None yet
Development

No branches or pull requests

1 participant