Skip to content

Commit 9cc6d70

Browse files
author
Baelx
authored
Corrected grammatical errors, refined prose style
1 parent 364e707 commit 9cc6d70

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

1-js/09-classes/02-class/article.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# Classes
33

4-
The "class" construct allows to define prototype-based classes with a clean, nice-looking syntax. It also introduces new great features, useful for object-oriented programming.
4+
The "class" construct allows one to define prototype-based classes with a clean, nice-looking syntax. It also introduces great new features which are useful for object-oriented programming.
55

66
## The "class" syntax
77

@@ -22,7 +22,7 @@ let user = new User("John");
2222
user.sayHi();
2323
```
2424

25-
...And that's the same using `class` syntax:
25+
...And here's the same using `class` syntax:
2626

2727
```js run
2828
class User {
@@ -41,17 +41,17 @@ let user = new User("John");
4141
user.sayHi();
4242
```
4343

44-
It's easy to see that the two examples are alike. Just please note that methods in a class do not have a comma between them. Novice developers sometimes forget it and put a comma between class methods, and things don't work. That's not a literal object, but a class syntax.
44+
It's easy to see that these two examples are alike. Be sure to note that methods in a class do not have a comma between them. A common pitfall for novice developers is to put a comma between class methods, which would result in a syntax error. The above are not actually objects but simply making use of a class syntax. This notation is primarily syntactical sugar.
4545

4646
## What is a class?
4747

4848
So, what exactly is a `class`? We may think that it defines a new language-level entity, but that would be wrong.
4949

5050
In Javascript, a class is a kind of a function.
5151

52-
The definition `class User {...}` create such function and puts the methods into `User.prototype`. So the structure is similar.
52+
The definition `class User {...}` creates a function under the same name and puts the methods into `User.prototype`. So the structure is similar.
5353

54-
Here's the code to dig into the class and see that:
54+
This is demonstrated in the following code, which you can run yourself:
5555

5656
```js run
5757
class User {
@@ -75,17 +75,17 @@ alert(User === User.prototype.constructor); // true
7575
alert(Object.getOwnPropertyNames(User.prototype)); // constructor, sayHi
7676
```
7777

78-
Here's the illustration of what `class User` creates:
78+
Abstractly, we can illustrate this process of `class User` creating a function as:
7979

8080
![](class-user.png)
8181

82-
So `class` is a special syntax to define a constructor together with its prototype methods. There are also quite a few additional features here and there, we'll study them later on.
82+
`Class` is a special syntax to define a constructor together with its prototype methods. In addition to its basic operation, the `Class` syntax brings many other features with it which we'll explore later.
8383

8484
## Class Expression
8585

8686
Just like functions, classes can be defined inside another expression, passed around, returned etc.
8787

88-
Here's a class-returning function ("class factory"):
88+
Here's a class-returning function - otherwise known as a "class factory":
8989

9090
```js run
9191
function makeClass(phrase) {
@@ -121,7 +121,7 @@ new User().sayHi(); // works, shows MyClass definition
121121
alert(MyClass); // error, MyClass not visible outside of the class
122122
```
123123

124-
## Differences of classes vs functions
124+
## Differences between classes and functions
125125

126126
Classes have some differences compared to regular functions:
127127

@@ -146,7 +146,7 @@ Class methods are non-enumerable
146146
: A class definition sets `enumerable` flag to `false` for all methods in the `"prototype"`. That's good, because if we `for..in` over an object, we usually don't want its class methods.
147147

148148
Classes have a default `constructor() {}`
149-
: If there's no `constructor` in the `class` construct, then an empty function is generated, same as if we had written `constructor() {}`.
149+
: If there's no `constructor` in the `class` construct, then an empty function is generated, just as if we had written `constructor() {}`.
150150

151151
Classes always `use strict`
152152
: All code inside the class construct is automatically in strict mode.
@@ -225,10 +225,10 @@ For a generator method, similarly, prepend it with `*`.
225225
## Class properties
226226

227227
```warn header="Old browsers may need a polyfill"
228-
Class-level properties is a recent addition to the language.
228+
Class-level properties are a recent addition to the language.
229229
```
230230

231-
In the example before, `User` only had methods. Let's add a property:
231+
In the example above, `User` only had methods. Let's add a property:
232232

233233
```js run
234234
class User {

0 commit comments

Comments
 (0)