Object.create()方法创建一个新对象,使用现有的对象来提供新创建的对象的proto。
手写一个Object.create
function _create (o) {
fucntion Fn () {};
Fn.prototype = o;
return new Fn();
}
let newObj = _create(obj);
可以传参数的版本
function _create (o) {
let args = Array.prototype.slice(arguments, 1); // 拿到参数
for (let i in args) {
o.assign(o, i); // 循环参数浅拷贝给o
}
fucntion Fn () {};
Fn.prototype = o;
return new Fn(args);
}
let newObj = _create(obj);
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/create
https://blog.csdn.net/qq_44752117/article/details/105627378
https://www.jianshu.com/p/28d85bebe599 有关create和new的区别