所有的静态属性和静态方法不能继承,只能由所在类的类名调用
static 定义静态属性或方法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
</body>
<!-- ES6继承 -->
<script>
// 创建父类
class Father{
// 添加静态属性 静态属性不能继承
static address = '广州'
// 添加实例属性/方法
constructor(n1,a1){
this.name = n1
this.age = a1
this.go = function(){
console.log('会走')
}
}
// 添加原型方法
say(){
console.log('大家好')
}
// 添加静态方法 静态方法不能继承
static run(){
console.log('会跑')
}
}
// 创建子类并继承指定父类
class Son extends Father{
// 添加实例属性
constructor(n1,a1,s1){
// 调用super方法,生成子类的this
super(n1,a1)
this.sex = s1
}
// 创建子类原型方法
fn(){
console.log(666)
}
}
// 创建子类实例对象
var son = new Son('张三',18,'男')
console.log(son)
</script>
</html>