more typos

This commit is contained in:
Thierry Parmentelat 2017-06-01 08:17:51 +02:00
parent dc1a4fb6ad
commit fb6b393f0c
6 changed files with 23 additions and 23 deletions

View file

@ -43,7 +43,7 @@ let user = new User("John");
user.sayHi();
```
It's easy to see that the two examples are alike. So, what exactly the `class` does? We may think that it defines a new language-level entity, but that would be wrong.
It's easy to see that the two examples are alike. So, what exactly does `class` do? We may think that it defines a new language-level entity, but that would be wrong.
The `class User {...}` here actually does two things:
@ -98,11 +98,11 @@ Class definition sets `enumerable` flag to `false` for all methods in the `"prot
```
```smart header="What if there's no constructor?"
If there's no `constructor` in the `class` construct, then an empty function is generated, same as if write `constructor() {}`.
If there's no `constructor` in the `class` construct, then an empty function is generated, same as if we had written `constructor() {}`.
```
```smart header="Classes always `use strict`"
All code inside the class construct is automatically in the strict mode.
All code inside the class construct is automatically in strict mode.
```
### Getters/setters
@ -273,7 +273,7 @@ articles.sort(Article.compare);
alert( articles[0].title ); // Body
```
Here `Article.compare` stands "over" the articles, as a meants to compare them.
Here `Article.compare` stands "over" the articles, as a means to compare them.
Another example would be a so-called "factory" method, that creates an object with specific parameters.

View file

@ -163,7 +163,7 @@ setTimeout(function() { super.stop() }, 1000);
With constructors, things are is a little bit tricky.
Till now, `Rabbit` had no its own `constructor`.
Till now, `Rabbit` did not have its own `constructor`.
According to the [specification](https://tc39.github.io/ecma262/#sec-runtime-semantics-classdefinitionevaluation), if a class extends another class and has no `constructor`, then the following `constructor` is generated:
@ -271,7 +271,7 @@ Yeah, indeed, let's ask ourselves, how it could technically work? When an object
Maybe we can get it `[[Prototype]]` of `this`, as `this.__proto__.method`? Unfortunately, that won't work.
Let's try to do it. Without classes, using plain objects for sheer simplicity.
Let's try to do it. Without classes, using plain objects for the sake of simplicity.
Here, `rabbit.eat()` should call `animal.eat()` method of the parent object:

View file

@ -117,7 +117,7 @@ alert( rabbit instanceof Rabbit ); // false
*/!*
```
That's one of reasons to evade changing `prototype`. Just to keep safe.
That's one of reasons to avoid changing `prototype`. Just to keep safe.
## Bonus: Object toString for the type

View file

@ -47,7 +47,7 @@ new User("Dude").sayHi(); // Hi Dude!
There's no inheritance, there's a simple method copying. So `User` may extend some other class and also include the mixin to "mix-in" the additional methods.
Mixins also can also make use of inheritance.
Mixins also can make use of inheritance.
For instance, here `sayHiMixin` inherits from `sayMixin`:
@ -98,7 +98,7 @@ Now a mixin for the real life.
The important feature of many objects is working with events.
That is: an object should have a method to "generate an event" when something important happens to him, and other objects should be able to "subscribe" to receive such notifications.
That is: an object should have a method to "generate an event" when something important happens to it, and other objects should be able to "subscribe" to receive such notifications.
An event must have a name and, if necessary, the attached data.
@ -108,7 +108,7 @@ Or, the object `menu` can generate the event `"select"` when a menu item is sele
Events is a way to "share information" with anyone who wants it.
The `eventMixin` to implement the corresponding methods:
Here is `eventMixin` that implements the corresponding methods:
```js run
let eventMixin = {
@ -156,7 +156,7 @@ let eventMixin = {
There are 3 methods here:
1. `.on(eventName, handler)` -- assigns the function `handler` to run when the event with that name happens. The handlers are stored in `_eventHandlers` property.
1. `.on(eventName, handler)` -- assigns function `handler` to run when the event with that name happens. The handlers are stored in the `_eventHandlers` property.
2. `.off(eventName, handler)` -- removes the function from the handlers list.
3. `.trigger(eventName, ...args)` -- generates the event: all assigned handlers are called and `args` are passed as arguments to them.
@ -192,8 +192,8 @@ And the `eventMixin` can add such behavior to as many classes as we'd like, with
*Mixin* -- is a generic object-oriented programming term: a class that contains methods for other classes.
In JavaScript that can be implemented as copying them into the prototype.
Some other languages like e.g. python allow to create mixins using multiple inheritance. JavaScript does not support multiple inheritance, but mixins can be implemented by copying them into the prototype.
We can use mixins as a way to augment a class by multiple behaviors like event-handling that we overlooked above.
We can use mixins as a way to augment a class by multiple behaviors, like event-handling as we have seen above.
Mixins may become a point of conflict if they occasionally overwrite native class methods. So generally one should think well about the naming for a mixin, to minimalize such possibility.
Mixins may become a point of conflict if they occasionally overwrite native class methods. So generally one should think well about the naming for a mixin, to minimize such possibility.