ES6 class 基本使用
阿新 • • 發佈:2018-10-08
str -c com doc console pre wid log col
<!DOCTYPE html>
<html lang="zh">
<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>ES6 class</title >
</head>
<body>
<script type="text/javascript">
class Person {
//實例方法
constructor(name) {
this.name = name;
}
//原型鏈方法
sayName() {
console.log( this.name)
}
}
//不存在變量提升
let tom = new Person(‘tom‘);
tom.sayName();
</script>
</body>
</html>
ES6 class 基本使用