Replace Node.JS
with Node.js
This commit is contained in:
parent
b9ca311f19
commit
735880d45f
12 changed files with 17 additions and 17 deletions
|
@ -3,7 +3,7 @@
|
|||
|
||||
The global object provides variables and functions that are available anywhere. Mostly, the ones that are built into the language or the host environment.
|
||||
|
||||
In a browser it is named "window", for Node.JS it is "global", for other environments it may have another name.
|
||||
In a browser it is named "window", for Node.js it is "global", for other environments it may have another name.
|
||||
|
||||
For instance, we can call `alert` as a method of `window`:
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ There are two methods for it:
|
|||
- `setTimeout` allows to run a function once after the interval of time.
|
||||
- `setInterval` allows to run a function regularly with the interval between the runs.
|
||||
|
||||
These methods are not a part of JavaScript specification. But most environments have the internal scheduler and provide these methods. In particular, they are supported in all browsers and Node.JS.
|
||||
These methods are not a part of JavaScript specification. But most environments have the internal scheduler and provide these methods. In particular, they are supported in all browsers and Node.js.
|
||||
|
||||
|
||||
## setTimeout
|
||||
|
@ -99,7 +99,7 @@ clearTimeout(timerId);
|
|||
alert(timerId); // same identifier (doesn't become null after canceling)
|
||||
```
|
||||
|
||||
As we can see from `alert` output, in a browser the timer identifier is a number. In other environments, this can be something else. For instance, Node.JS returns a timer object with additional methods.
|
||||
As we can see from `alert` output, in a browser the timer identifier is a number. In other environments, this can be something else. For instance, Node.js returns a timer object with additional methods.
|
||||
|
||||
Again, there is no universal specification for these methods, so that's fine.
|
||||
|
||||
|
@ -382,7 +382,7 @@ First timers run immediately (just as written in the spec), and then the delay c
|
|||
|
||||
That limitation comes from ancient times and many scripts rely on it, so it exists for historical reasons.
|
||||
|
||||
For server-side JavaScript, that limitation does not exist, and there exist other ways to schedule an immediate asynchronous job, like [process.nextTick](https://nodejs.org/api/process.html) and [setImmediate](https://nodejs.org/api/timers.html) for Node.JS. So the notion is browser-specific only.
|
||||
For server-side JavaScript, that limitation does not exist, and there exist other ways to schedule an immediate asynchronous job, like [process.nextTick](https://nodejs.org/api/process.html) and [setImmediate](https://nodejs.org/api/timers.html) for Node.js. So the notion is browser-specific only.
|
||||
````
|
||||
|
||||
### Allowing the browser to render
|
||||
|
|
|
@ -37,7 +37,7 @@ let f = user.sayHi;
|
|||
setTimeout(f, 1000); // lost user context
|
||||
```
|
||||
|
||||
The method `setTimeout` in-browser is a little special: it sets `this=window` for the function call (for Node.JS, `this` becomes the timer object, but doesn't really matter here). So for `this.firstName` it tries to get `window.firstName`, which does not exist. In other similar cases as we'll see, usually `this` just becomes `undefined`.
|
||||
The method `setTimeout` in-browser is a little special: it sets `this=window` for the function call (for Node.js, `this` becomes the timer object, but doesn't really matter here). So for `this.firstName` it tries to get `window.firstName`, which does not exist. In other similar cases as we'll see, usually `this` just becomes `undefined`.
|
||||
|
||||
The task is quite typical -- we want to pass an object method somewhere else (here -- to the scheduler) where it will be called. How to make sure that it will be called in the right context?
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue