Object.create如何在Javascript中不允许多重继承?

Sta*_*tec 3 javascript inheritance

MDN给出了继承的javascipt的这种解释(与展示的原型链中的注释):

var a = {a: 1}; 
// a ---> Object.prototype ---> null

var b = Object.create(a);
// b ---> a ---> Object.prototype ---> null
console.log(b.a); // 1 (inherited)

var c = Object.create(b);
// c ---> b ---> a ---> Object.prototype ---> null

var d = Object.create(null);
// d ---> null
console.log(d.hasOwnProperty); 
// undefined, because d doesn't inherit from Object.prototype
Run Code Online (Sandbox Code Playgroud)

在这里,我认为c从多个类继承.这怎么不是多重继承?

dol*_*ldt 8

多重继承是指父级在层次结构中处于同一级别时:

c ---> b ---> Object.prototype ---> null
 \---> a ---> Object.prototype ---> null
Run Code Online (Sandbox Code Playgroud)

在这种情况下,它是从b继承自其他类的类继承的简单a:

c ---> b ---> a ---> Object.prototype ---> null
Run Code Online (Sandbox Code Playgroud)

附录:虽然效果可能看起来相似(b通过原型链中的查找也会在"c"中找到属性),但请注意多重继承允许的区别ab具有完全不同的继承链(实际上,继承"树") "),这在你的例子中显然不是这样.