class Person{
// 构造方法
constructor(name,id){
this.name = name
this.id = id
this.names = '张三'
}
// 方法
sayHello(){
console.log('hellow i am' + this.name);
}
}
// new 实例
// var person = new Person('张三','123456')
// console.log(person);
// 子继承父
class Son extends Person{
constructor(){
super('son1','9999')
this.height = '180'
}
}
var son1 = new Son()
console.log(son1);
文章介绍了JavaScript中的类(class)概念,包括构造方法的使用,以及如何创建一个子类(Son)继承自父类(Person),并通过实例化展示继承属性和方法的应用。
292

被折叠的 条评论
为什么被折叠?



