<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
</body>
<script>
class Father {
constructor(x, y) {
this.x = x
this.y = y
}
sum() {
console.log(this.x + this.y)
}
}
class Son extends Father{
constructor(x,y){
super(x,y) // 调用父类的构造函数
}
}
let son = new Son(2,5)
son.sum()
</script>
</html>
Clsss继承
最新推荐文章于 2023-08-03 23:19:55 发布