1.题目要求( 基于ES6中的class重构下面的代码)
function Modal(x,y){
this.x=x;
this.y=y;
}
Modal.prototype.z=10;
Modal.prototype.getX=function(){
console.log(this.x);
}
Modal.prototype.getY=function(){
console.log(this.y);
}
Modal.n=200;
Modal.setNumber=function(n){
this.n=n;
};
let m = new Model(10,20);
2.实现方法
class Modal {
constructor(x, y) {
this.x = x;
this.y = y;
}
getX() {
console.log(this.x);
}
getY() {
console.log(this.y);
}
static n = 200;
static setNumber(n) {
this.n = n;
}
}
Modal.prototype.z = 10;
let m = new Modal(10, 20);