构造函数法
缺点,用到了this和prototype,编写复杂,可读性差
function Per(name,age) {
this.name = name;
this.age = age;
}
Per.prototype.sell = function () { }
var per = new Per('zhangsan',32);
per.sell()
ES6语法糖class
class Point{
constructor(x,y){
this.x = x;
this.y = y;
}
toString(){
return '('+this.x+','+this.y+')';
}
}
var point = new Point(2,3)