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

Object.create实现 | 开箱即用的代码块 #27

Open
OBKoro1 opened this issue Aug 26, 2019 · 0 comments
Open

Object.create实现 | 开箱即用的代码块 #27

OBKoro1 opened this issue Aug 26, 2019 · 0 comments

Comments

@OBKoro1
Copy link
Owner

OBKoro1 commented Aug 26, 2019

博客链接

# Object.create实现

# 关键思路:

将传入的对象作为新对象原型

# 代码:

function myCreate(obj) {
  function F() {}
  F.prototype = obj
  return new F()
}

# 修改原对象的属性会影响新对象的原型:

var obj1 = { p: 1 };
var obj2 = Object.create(obj1);
obj1.p = 2;
console.log('obj', obj1, obj2,)

# 点个Star支持我一下~

博客链接

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

No branches or pull requests

1 participant