法一:
B.prototype = new A();
B.prototype.constructor = B;
相當(dāng)于
B: { prototype: { constructor: B }, __proto__: { __proto__: A.prototype: { __proto__: ... } } }
法二:
B.prototype = Object.create(A.prototype);
Object.create(o)
相當(dāng)于內(nèi)部創(chuàng)建一個新的函數(shù)镀裤,然后將這個函數(shù)的prototype置為o握牧,然后返回由這個函數(shù)創(chuàng)建的實(shí)例
那么整個過程相當(dāng)于
function F() {}
F.prototype = A.prototype;
B.prototype = new F();
B: { prototype: { constructor: B }, __proto__: { __proto__: F.prototype[A.prototype] : { __proto__: ... } } }