Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 08b833d commit f821facCopy full SHA for f821fac
advanced/class.md
@@ -70,20 +70,21 @@ console.log(c.sayHi()); // Meow, My name is Tom
70
71
```javascript
72
class Animal {
73
- constructor(name) {
74
- this.name = name;
75
- }
76
- get name() {
77
- return 'Jack';
78
79
- set name(value) {
80
- console.log('setter: ' + value);
81
+ constructor(name) {
+ this._name = name;
+ }
+ get name() {
+ return this._name;
+ set name(value) {
+ this._name = value
+ console.log('setter: ' + value);
82
83
}
84
-let a = new Animal('Kitty'); // setter: Kitty
85
+let a = new Animal('Jack');
86
a.name = 'Tom'; // setter: Tom
-console.log(a.name); // Jack
87
+console.log(a.name); // Tom
88
```
89
90
### 靜態方法
0 commit comments