54 lines
1.1 KiB
HTML
54 lines
1.1 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( name ,shengaoP ,miaosu){
|
||
|
|
||
|
//设置属性
|
||
|
this.name =name;
|
||
|
this.shengaoP= shengaoP;
|
||
|
this.miaosu=miaosu;
|
||
|
}
|
||
|
//设置方法
|
||
|
hit = (itx="别人")=>{
|
||
|
console.log(`${this.name}打->${itx}`);
|
||
|
}
|
||
|
|
||
|
//设置私有属性
|
||
|
static v =function() {
|
||
|
return "1.2.3"
|
||
|
};
|
||
|
|
||
|
// 注意 低版本的浏览器内核不支持
|
||
|
static xxx = "xxx";
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
}
|
||
|
let Ultraman =new Animal("奥特曼",80,"来自光之国的打怪头");
|
||
|
Ultraman.hit("怪兽");
|
||
|
console.log(Ultraman);
|
||
|
|
||
|
let tiger = new Animal("老虎",1.2,"来自大山深处的王者");
|
||
|
tiger.hit("武松");
|
||
|
console.log(tiger);
|
||
|
|
||
|
</script>
|
||
|
|
||
|
</body>
|
||
|
</html>
|