<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script>
class getMsg{
constructor(a,b){
this.x = a;
this.y = b;
}
getNum(){
return this.x * this.y
}
}
var num = new getMsg(2,3);
console.log(num); // getMsg {a: 2, b: 3}
console.log(num.getNum()); // 6
</script>
</body>
</html>
复制代码
ES6 类的使用(class)
最新推荐文章于 2024-04-12 07:18:50 发布