You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// proof: there are two methods in its "prototype"
@@ -129,7 +129,7 @@ class User {
129
129
setname(value) {
130
130
*/!*
131
131
if (value.length<4) {
132
-
alert("Name too short.");
132
+
alert("Name is too short.");
133
133
return;
134
134
}
135
135
this._name= value;
@@ -146,7 +146,7 @@ user = new User(""); // Name too short.
146
146
Internally, getters and setters are also created on the `User` prototype, like this:
147
147
148
148
```js
149
-
Object.defineProperty(User.prototype, {
149
+
Object.defineProperties(User.prototype, {
150
150
name: {
151
151
get() {
152
152
returnthis._name
@@ -239,7 +239,7 @@ class User {
239
239
*!*
240
240
staticstaticMethod() {
241
241
*/!*
242
-
alert(this== User);
242
+
alert(this=== User);
243
243
}
244
244
}
245
245
@@ -252,7 +252,7 @@ That actually does the same as assigning it as a function property:
252
252
functionUser() { }
253
253
254
254
User.staticMethod=function() {
255
-
alert(this== User);
255
+
alert(this=== User);
256
256
};
257
257
```
258
258
@@ -312,7 +312,7 @@ class Article {
312
312
*!*
313
313
staticcreateTodays() {
314
314
// remember, this = Article
315
-
returnnewthis("Todays digest", newDate());
315
+
returnnewthis("Today's digest", newDate());
316
316
}
317
317
*/!*
318
318
}
@@ -322,7 +322,7 @@ let article = Article.createTodays();
322
322
alert( article.title ); // Todays digest
323
323
```
324
324
325
-
Now every time we need to create a todays digest, we can call `Article.createTodays()`. Once again, that's not a method of an article, but a method of the whole class.
325
+
Now every time we need to create a today's digest, we can call `Article.createTodays()`. Once again, that's not a method of an article, but a method of the whole class.
326
326
327
327
Static methods are also used in database-related classes to search/save/remove entries from the database, like this:
0 commit comments