Merge pull request #1322 from Dayun123/Dayun123-javascript.info--ch.4-grammar-patch

Dayun123 javascript.info  ch.4 grammar patch
This commit is contained in:
Ilya Kantor 2019-09-07 23:07:52 +03:00 committed by GitHub
commit 1268643c6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -167,9 +167,9 @@ If we used `this.name` instead of `user.name` inside the `alert`, then the code
## "this" is not bound
In JavaScript, "this" keyword behaves unlike most other programming languages. It can be used in any function.
In JavaScript, the "this" keyword behaves unlike most other programming languages. It can be used in any function.
There's no syntax error in the code like that:
There's no syntax error in the following example:
```js
function sayHi() {
@ -226,7 +226,7 @@ Usually such call is a programming error. If there's `this` inside a function, i
```smart header="The consequences of unbound `this`"
If you come from another programming language, then you are probably used to the idea of a "bound `this`", where methods defined in an object always have `this` referencing that object.
In JavaScript `this` is "free", its value is evaluated at call-time and does not depend on where the method was declared, but rather on what's the object "before the dot".
In JavaScript `this` is "free", its value is evaluated at call-time and does not depend on where the method was declared, but rather on what object is "before the dot".
The concept of run-time evaluated `this` has both pluses and minuses. On the one hand, a function can be reused for different objects. On the other hand, greater flexibility opens a place for mistakes.