////////////原来的js创建构造方法
function Cat() { //构造器
this.age = 20;
this.name = "李白"
}
Cat.prototype.say = function() {
console.log("name", this.name)
}
let cat = new Cat()
cat.say() //name 李白
//////////////es6创建构造方法
class Dog {
constructor() { //构造器
this.name = "Dog";
this.color = "白色";
}
say() {
console.log("你是一只", this.name)
}
}
let dog = new Dog()
dog.say()
网友评论