// //類的定義
// class Animal {
// constructor(name){
// this.name= name ;
// }
// sayName(){
// console.log("我的名字是"+this.name);
// }
// }
// //類的繼承
// class People extends Animal {
// constructor(name){
// super(name) //用來新建this的指向
// } //在new對象生成實例時,必須調用這個方法 一般調用父類的construct
// PeopleSay(){
// console.log("我的名字是"+this.name)
// }
// }
// var dog = new Animal("dog")
// dog.sayName()
class Animal {
constructor(name){
this.name = name
}
eat(){
console.log("中午喫"+this.name)
}
}
class dog extends Animal{
constructor(name){
super(name)
}
dogSay(){
console.log("我想喫"+this.name)
}
}
var cat = new Animal("tom")
cat.eat()
var petter = new dog("pet")
petter.dogSay()
//construct是一類的構造函數
//通過new命令創建實例時,自動調用該對象 一般 construct指向實例對象