57 lines
1.3 KiB
HTML
57 lines
1.3 KiB
HTML
|
<!DOCTYPE html>
|
|||
|
<html lang="en">
|
|||
|
<head>
|
|||
|
<meta charset="UTF-8">
|
|||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|||
|
<title>Document</title>
|
|||
|
</head>
|
|||
|
<body>
|
|||
|
|
|||
|
<script>
|
|||
|
|
|||
|
//面向对象:封装, 继承 多态
|
|||
|
|
|||
|
// class 类名{}
|
|||
|
|
|||
|
class Animal {
|
|||
|
|
|||
|
//类的初始化 接受初始化的参数
|
|||
|
constructor( Aname ,shengaoPJ ,miaosu){
|
|||
|
|
|||
|
//设置属性
|
|||
|
this.Aname =Aname;
|
|||
|
this.shengaoPJ= shengaoPJ;
|
|||
|
this.miaosu=miaosu;
|
|||
|
}
|
|||
|
//设置方法
|
|||
|
hit = (itx="别人")=>{
|
|||
|
console.log(`${this.name}打->${itx}`);
|
|||
|
}
|
|||
|
|
|||
|
//设置私有属性
|
|||
|
static v =function() {
|
|||
|
return "1.2.3"
|
|||
|
};
|
|||
|
|
|||
|
// 注意 低版本的浏览器内核不支持
|
|||
|
static xxx = "xxx";
|
|||
|
}
|
|||
|
//初始化个体奥特曼
|
|||
|
class Ultraman extends Animal {
|
|||
|
constructor(Cname,shengaoPJ,jiesao){
|
|||
|
//父类 的初始化 , 可给父类传参
|
|||
|
super("奥特曼",80,"来自光之国的打怪头");
|
|||
|
this.Cname=Cname;
|
|||
|
this.shengaoPJ=shengaoPJ;
|
|||
|
this.jiesao=jiesao;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
let zeta = new Ultraman("泽塔",90,"来自光之国的打怪头");
|
|||
|
console.log(zeta);
|
|||
|
|
|||
|
|
|||
|
</script>
|
|||
|
|
|||
|
</body>
|
|||
|
</html>
|