object.create()
是使用指定的原型proto对象及其属性propertiesObject
去创建一个新的对象。1
2
3
4
5
6
7
8
9
10Object.myCreate = function (obj, properties) {
var F = function () {}
F.prototype = obj
if (properties) {
Object.defineProperties(F, properties)
}
return new F()
}
Object.myCreate({}, {a: {value: 1}}) // {a: 1}