Skip to content

Commit 89f6c41

Browse files
authored
Merge pull request #302 from usernamehw/patch-2
Update article.md
2 parents 4562330 + e842caf commit 89f6c41

File tree

1 file changed

+9
-9
lines changed
  • 1-js/07-object-oriented-programming/09-class

1 file changed

+9
-9
lines changed

1-js/07-object-oriented-programming/09-class/article.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The "class" construct allows to define prototype-based classes with a clean, nic
77

88
## The "class" syntax
99

10-
The `class` syntax is versatile, we'll start from a simple example first.
10+
The `class` syntax is versatile, we'll start with a simple example first.
1111

1212
Here's a prototype-based class `User`:
1313

@@ -57,13 +57,13 @@ Here's the code to dig into the class and see that:
5757
```js run
5858
class User {
5959
constructor(name) { this.name = name; }
60-
sayHi() { alert(this.name); }
60+
sayHi() { alert(this.name); }
6161
}
6262

6363
*!*
6464
// proof: User is the "constructor" function
6565
*/!*
66-
alert(User == User.prototype.constructor); // true
66+
alert(User === User.prototype.constructor); // true
6767

6868
*!*
6969
// proof: there are two methods in its "prototype"
@@ -129,7 +129,7 @@ class User {
129129
set name(value) {
130130
*/!*
131131
if (value.length < 4) {
132-
alert("Name too short.");
132+
alert("Name is too short.");
133133
return;
134134
}
135135
this._name = value;
@@ -146,7 +146,7 @@ user = new User(""); // Name too short.
146146
Internally, getters and setters are also created on the `User` prototype, like this:
147147

148148
```js
149-
Object.defineProperty(User.prototype, {
149+
Object.defineProperties(User.prototype, {
150150
name: {
151151
get() {
152152
return this._name
@@ -239,7 +239,7 @@ class User {
239239
*!*
240240
static staticMethod() {
241241
*/!*
242-
alert(this == User);
242+
alert(this === User);
243243
}
244244
}
245245

@@ -252,7 +252,7 @@ That actually does the same as assigning it as a function property:
252252
function User() { }
253253

254254
User.staticMethod = function() {
255-
alert(this == User);
255+
alert(this === User);
256256
};
257257
```
258258

@@ -312,7 +312,7 @@ class Article {
312312
*!*
313313
static createTodays() {
314314
// remember, this = Article
315-
return new this("Todays digest", new Date());
315+
return new this("Today's digest", new Date());
316316
}
317317
*/!*
318318
}
@@ -322,7 +322,7 @@ let article = Article.createTodays();
322322
alert( article.title ); // Todays digest
323323
```
324324

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.
326326

327327
Static methods are also used in database-related classes to search/save/remove entries from the database, like this:
328328

0 commit comments

Comments
 (0)