<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>类继承</title>
</head>
<body>
<h3>类继承</h3>
<p id = "类继承"></p>
<script>
class Baidu {
constructor(hh) {
this.zjbj = hh;
}
get dmbj() {
return this.zjbj;
}
set dmbj(r) {
this.zjbj = r;
}
}
let css = new Baidu("终极笔记");
document.getElementById("类继承").innerHTML = css.dmbj;
</script>
</body>
</html>
JavaScript 类继承
getter 和 setter
类中我们可以使用 getter 和 setter 来
获取和设置值,getter 和 setter 都需要在严格模式下执行。
getter 和 setter 可以使得我们对属性的操作变的很灵活
类还允许您使用 getter 和 setter。
为您的属性使用 getter 和 setter 很聪明,
特别是如果您想在返回它们之前或在设置它们
之前对值做一些特殊的事情。
如需在类中添加 getter 和 setter
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>类继承</title>
</head>
<body>
<h3>类继承</h3>
<p id = "类继承0"></p>
<script>
class Baidu {
constructor(cf) {
this._zjbj = cf;
}
get dmbj() {
return this._zjbj;
}
set dmbj(cs) {
this._zjbj = cs;
}
}
let baidu = new Baidu("盗墓笔记");
document.getElementById("类继承0").innerHTML = baiu.dmbj;
</script>
</body>
</html>
JavaScript 类继承
getter 和 setter
类中我们可以使用 getter 和 setter 来
获取和设置值,getter 和 setter 都需要在严格模式下执行。
getter 和 setter 可以使得我们对属性的操作变的很灵活
类还允许您使用 getter 和 setter。
为您的属性使用 getter 和 setter 很聪明,
特别是如果您想在返回它们之前或在设置它们
之前对值做一些特殊的事情。
如需在类中添加 getter 和 setter
get 和 set 关键字
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>类继承</title>
</head>
<body>
<h3>类继承</h3>
<p id = "类继承1"></p>
<script>
class Baidu {
constructor(uu) {
this._zjbj = uu;
}
set sh(q) {
this._zjbj = q;
}
get sh() {
return this._zjbj;
}
}
let baidu = new Baidu("百度");
baidu.sh = "盗墓笔记";
document.getElementById("类继承1").innerHTML = baidu.sh;
</script>
</body>
</html>
JavaScript 类继承
getter 和 setter
类中我们可以使用 getter 和 setter 来
获取和设置值,getter 和 setter 都需要在严格模式下执行。
getter 和 setter 可以使得我们对属性的操作变的很灵活
类还允许您使用 getter 和 setter。
为您的属性使用 getter 和 setter 很聪明,
特别是如果您想在返回它们之前或在设置它们
之前对值做一些特殊的事情。
如需在类中添加 getter 和 setter
get 和 set 关键字