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:
commit
1268643c6a
1 changed files with 3 additions and 3 deletions
|
@ -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.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue