JavaScript设计模式(biaoyansu)

1.构造器模式

1.构造器模式

ES6:
class Student{
constructor(score,quality){
this.score = score
this.quality = quality
}
sumScore(){
return this.score + this.quality
}
}

ES5:
function Student(name,gender,score){
this.name = name;
this.gende = gender;
this.score = score;
this.quality = 100;

this.sumScore = function() {
return this.score + this.quality
}
}

面向对象的思想

每个对象可以随着事件的推移自己内在发生变化而不去影响其他对象

猜你喜欢

转载自www.cnblogs.com/eret9616/p/9649266.html