ES6的class
class Studen {
constructor(name,number){
this.name = name;
this.number = number;
}
sayHi() {
console.log(`姓名${this.name},学号${this.number}`)
}
}
const xialuo = new Student('夏洛',100)
console.log(xialuo.name)
console.log(xialuo.number)
xialuo.sayHi()
继承
class People{
constructor(name){
this.name = name;
}
eat(){
console.log(`${this.name} eat something`)
}
}
class student extends People{
constructor(name,number){
super(name)
this.number = number
}
sayHi() {
console.log(`姓名${this.name} 学号 ${this.number}`)
}
}
const xialuo = new Student('夏洛',100)
console.log(xialuo.name)
console.log(xialuo.number)
xialuo.sayHi()
xialuo.eat()
类型判断-instanceof
xialuo instanceof Student
xialuo instanceof People
xialuo instanceof Object
[] instanceof Array
[] instanceof Object
{} instanceof Object