25.类的静态成员
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
// function Phone() {}
// Phone.name = "手机";
// Phone.change = function () {
// console.log("改变自己,改变全世界");
// };
// Phone.prototype.size = "666";
// let nokia = new Phone();
// console.log(nokia.name); 实例对象和函数对象自身的属性是不相通的
// console.log(nokia.size);
class Phone {
// 静态属性,static关键字表示这个成员属于类本身,而不属于实例对象,和ES5类似
static name = "手机";
static change() {
console.log("改变自己,改变全世界");
}
}
let apple = new Phone();
console.log(apple.name);
console.log(Phone.name);
</script>
</body>
</html>