You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
function Super() {}
function Sub() {}
Sub.prototype = new Super();
Sub.prototype.constructor = Sub;
var sub = new Sub();
Sub.prototype.constructor === Sub; // ② true
sub.constructor === Sub; // ④ true
sub.__proto__ === Sub.prototype; // ⑤ true
Sub.prototype.__proto__ == Super.prototype; // ⑦ true
ES6
ES6中的继承,看图:
class Super {}
class Sub extends Super {}
var sub = new Sub();
Sub.prototype.constructor === Sub; // ② true
sub.constructor === Sub; // ④ true
sub.__proto__ === Sub.prototype; // ⑤ true
Sub.__proto__ === Super; // ⑥ true
Sub.prototype.__proto__ === Super.prototype; // ⑦ true
ES5
ES5中的继承,看图:
![image](https://cloud.githubusercontent.com/assets/12530172/25800935/ed2b8054-341d-11e7-9109-a7e00128d4ec.png)
ES6
ES6中的继承,看图:
![image](https://cloud.githubusercontent.com/assets/12530172/25800991/38d78fb6-341e-11e7-843d-80ab9152de36.png)
所以
ES6和ES5的继承是一模一样的,只是多了class 和extends ,ES6的子类和父类,子类原型和父类原型,通过__proto__ 连接。
原文链接:ES5和ES6中的继承
The text was updated successfully, but these errors were encountered: