remove cut
This commit is contained in:
parent
37f1936622
commit
be007e78ef
99 changed files with 0 additions and 198 deletions
|
@ -10,8 +10,6 @@ Recursion is a programming pattern that is useful in situations when a task can
|
|||
|
||||
When a function solves a task, in the process it can call many other functions. A partial case of this is when a function calls *itself*. That's called *recursion*.
|
||||
|
||||
[cut]
|
||||
|
||||
## Two ways of thinking
|
||||
|
||||
For something simple to start with -- let's write a function `pow(x, n)` that raises `x` to a natural power of `n`. In other words, multiplies `x` by itself `n` times.
|
||||
|
|
|
@ -10,8 +10,6 @@ For instance:
|
|||
|
||||
In this chapter we'll learn how to do the same. And, more importantly, how to feel comfortable working with such functions and arrays.
|
||||
|
||||
[cut]
|
||||
|
||||
## Rest parameters `...`
|
||||
|
||||
A function can be called with any number of arguments, no matter how it is defined.
|
||||
|
|
|
@ -11,8 +11,6 @@ Also, what happens when a function travels to another place in the code and is c
|
|||
|
||||
Different languages behave differently here, and in this chapter we cover the behaviour of JavaScript.
|
||||
|
||||
[cut]
|
||||
|
||||
## A couple of questions
|
||||
|
||||
Let's consider two situations to begin with, and then study the internal mechanics piece-by-piece, so that you'll be able to answer the following questions and more complex ones in the future.
|
||||
|
|
|
@ -13,8 +13,6 @@ But `var` is a very different beast, that originates from very old times. It's g
|
|||
|
||||
If you don't plan meeting such scripts you may even skip this chapter or postpone it, but then there's a chance that it bites you later.
|
||||
|
||||
[cut]
|
||||
|
||||
From the first sight, `var` behaves similar to `let`. That is, declares a variable:
|
||||
|
||||
```js run
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
|
||||
There's one more way to create a function. It's rarely used, but sometimes there's no alternative.
|
||||
|
||||
[cut]
|
||||
|
||||
## Syntax
|
||||
|
||||
The syntax for creating a function:
|
||||
|
|
|
@ -10,8 +10,6 @@ There are two methods for it:
|
|||
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.
|
||||
|
||||
|
||||
[cut]
|
||||
|
||||
## setTimeout
|
||||
|
||||
The syntax:
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
JavaScript gives exceptional flexibility when dealing with functions. They can be passed around, used as objects, and now we'll see how to *forward* calls between them and *decorate* them.
|
||||
|
||||
[cut]
|
||||
|
||||
## Transparent caching
|
||||
|
||||
Let's say we have a function `slow(x)` which is CPU-heavy, but its results are stable. In other words, for the same `x` it always returns the same result.
|
||||
|
|
|
@ -9,8 +9,6 @@ When using `setTimeout` with object methods or passing object methods along, the
|
|||
|
||||
Suddenly, `this` just stops working right. The situation is typical for novice developers, but happens with experienced ones as well.
|
||||
|
||||
[cut]
|
||||
|
||||
## Losing "this"
|
||||
|
||||
We already know that in JavaScript it's easy to lose `this`. Once a method is passed somewhere separately from the object -- `this` is lost.
|
||||
|
|
|
@ -9,8 +9,6 @@ Till now we were only talking about binding `this`. Now let's make a step furthe
|
|||
|
||||
We can bind not only `this`, but also arguments. That's rarely done, but sometimes can be handy.
|
||||
|
||||
[cut]
|
||||
|
||||
The full syntax of `bind`:
|
||||
|
||||
```js
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
Let's revisit arrow functions.
|
||||
|
||||
[cut]
|
||||
|
||||
Arrow functions are not just a "shorthand" for writing small stuff.
|
||||
|
||||
JavaScript is full of situations where we need to write a small function, that's executed somewhere else.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue