function inherit(p){
if(p === null)
throw TypeError;
if(Object.create)
return Object.create(p); //创建对象可用Object.create方法
const p = typeof p;
if(p !== 'object' && p !== 'function')
throw TypeError;
function f(){}
f.prototype = p;
return new f();
}
let a = {};
a.x = 1;
let b = inherit(a); // b继承a和Object.prototype;
b.y = 2;
let c = inherit(b); // c继承a,b和Object.prototype;
c.z = 3;
c.x + c.y + c.z // 1 + 2 + 3 = 6;
Object.create()方法 : 创建一个新对象,第一个参数为这个对象的原型,第二个为可选参数,用来对对象属性进行进一步描述;