ES6中的类只是语法糖,它并没有改变类实现的本质。
举个例子,在ES5中定义一个类:
function Person(name) {this.name name;
}Person.prototype.sayHello function(){return Hi, I am this.name;
}
而用ES6的写法重写一下,检…
ES5四种继承方式ES6类继承
一.借用构造函数
主要用到的原理:使用call函数改变this指向
function Parent() {this.name qx;
}
function Child(age) {Parent.call(this);this.age age;
}
var c new Child(19);
console.log(c.name); //qx原理就是在Child的构造函…