ES6 类的使用(class)

159 阅读1分钟
<!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>