Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/arrow-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Lovingly called the *fat arrow* (becuase `->` is a thin arrow and `=>` is a fat arrow) and also called a *lambda function* (because of other languages). Another commonly used feature is the fat arrow function `()=>something`. The motivation for a *fat arrow* is:
1. You don't need to keep typing `function`
1. I lexically captures the meaning of `this`
2. It lexically captures the meaning of `this`

For a language that claims to be functional, in JavaScript you tend to be typing `function` quite a lot. The fat arrow makes it simple for you to create a function
```ts
Expand Down Expand Up @@ -76,4 +76,4 @@ person.growOld();
```
then `this` is going to be the correct calling context (in this example `person`).

{% include "footer.md" %}
{% include "footer.md" %}
4 changes: 2 additions & 2 deletions docs/classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ console.log(Foo.prototype); // {} i.e. it exists and is not undefined
console.log(Foo.prototype.constructor === Foo); // Has a member called `constructor` pointing back to the function
```

Now lets look at *effect of `new` on `this` inside the called function*. Basically `this` inside the called function is going to point to the newly created object that will be returned from the function. Its simple to see if you mutate a property on `this` inside the function:
Now lets look at *effect of `new` on `this` inside the called function*. Basically `this` inside the called function is going to point to the newly created object that will be returned from the function. It's simple to see if you mutate a property on `this` inside the function:

```ts
function Foo() {
Expand Down Expand Up @@ -270,7 +270,7 @@ But wait we wanted `d.prototype.__proto__` i.e. just the proto changed and maint

#### `d.prototype.__proto__ = b.prototype` significance

The significance is that it allows you to add members functions to a child class and inherit other from the base class. This is demonstrated by the following simple example:
The significance is that it allows you to add member functions to a child class and inherit others from the base class. This is demonstrated by the following simple example:

```ts
function Animal() { }
Expand Down
4 changes: 2 additions & 2 deletions docs/destructuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var rect = { x: 0, y: 10, width: 15, height: 20 };
var {x, y, width, height} = rect;
console.log(x, y, width, height); // 0,10,15,20
```
Here in the absence of destructing you would have to pick off `x,y,width,height` one by one from `rect`.
Here in the absence of destructuring you would have to pick off `x,y,width,height` one by one from `rect`.

#### Array Destructuring
A common programming question : Swap two variables without using a third one. The TypeScript solution:
Expand Down Expand Up @@ -59,7 +59,7 @@ var _a;
```

#### Summary
Destructuring can make your code more readable and maintainable by reducing the line count and making the intent clear. Array destructuring can allow to use arrays as though they were tuples.
Destructuring can make your code more readable and maintainable by reducing the line count and making the intent clear. Array destructuring can allow you to use arrays as though they were tuples.


{% include "footer.md" %}
2 changes: 1 addition & 1 deletion docs/for...of.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ for (let paragraph of articleParagraphs) {
Use `for...of` only for stuff that *you know* to be an array or a string. Note that this limitation might be removed in a future version of TypeScript.

#### Summary
You would be surprised at how many times you will be iterating over the elements of an array. The next time you find yourself doing that, give `for...of` a go. You might just make the next person who reviews you code happy.
You would be surprised at how many times you will be iterating over the elements of an array. The next time you find yourself doing that, give `for...of` a go. You might just make the next person who reviews your code happy.

{% include "footer.md" %}
4 changes: 2 additions & 2 deletions docs/let.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ for (var j = 0; j < 3; j++) {
funcs[j]();
}
```
Here the functions close over (hence called a `closure`) the *local* variable (conviniently named `local`) and use that instead of the loop variable `i`. Note that closures come with a performance impact (they need to store the surrounding state) and therefore even though the ES6 `let` keyword in a loop would have the same behavior as the previous example, the following is an error in TypeScript if you target something less that ES6:
Here the functions close over (hence called a `closure`) the *local* variable (conveniently named `local`) and use that instead of the loop variable `i`. Note that closures come with a performance impact (they need to store the surrounding state) and therefore even though the ES6 `let` keyword in a loop would have the same behavior as the previous example, the following is an error in TypeScript if you target something less than ES6:

```ts
var funcs = [];
Expand All @@ -133,4 +133,4 @@ Despite a few limitations, we find `let` to be extremely useful to have for the

{% include "footer.md" %}

[](https://github.com/olov/defs/blob/master/loop-closures.md)
[](https://github.com/olov/defs/blob/master/loop-closures.md)
4 changes: 2 additions & 2 deletions docs/spread-operator.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The main objective of the spread operator is to *spread* the objects of an array. This is best explained with examples.

#### Apply
A common use case it to spread an array into the function arguments. Previously you would need to use `Function.prototype.apply`:
A common use case is to spread an array into the function arguments. Previously you would need to use `Function.prototype.apply`:

```ts
function foo(x, y, z) { }
Expand Down Expand Up @@ -40,6 +40,6 @@ console.log(list); // [1,2,3,4]
```

#### Summary
`apply` is something that you would inevitably do in JavaScript, so its good to have a better syntax where you don't have that ugly `null` for the `this` argument. Also having a dedicated syntax for moving arrays out of (destructuring) or into (assignment) other arrays provides neat syntax for when you are doing array processing on partial arrays.
`apply` is something that you would inevitably do in JavaScript, so it's good to have a better syntax where you don't have that ugly `null` for the `this` argument. Also having a dedicated syntax for moving arrays out of (destructuring) or into (assignment) other arrays provides neat syntax for when you are doing array processing on partial arrays.

{% include "footer.md" %}
6 changes: 3 additions & 3 deletions docs/template-strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Never gonna let you down`;
```

#### String Interpolation
Another common use case is when you want to generate some string out of some static strings + some variables. For this you would need some *templating logic* and this is where *template strings* get there name from. Here's how you would potentially generate an html string previously:
Another common use case is when you want to generate some string out of some static strings + some variables. For this you would need some *templating logic* and this is where *template strings* get their name from. Here's how you would potentially generate an html string previously:

```ts
var lyrics = 'Never gonna give you up';
Expand Down Expand Up @@ -77,6 +77,6 @@ function htmlEscape(literals, ...placeholders) {
For pre ES6 compile targets the code is fairly simple. Multiline strings become escaped strings. String interpolation becomes *string concatenation*. Tagged Templates become function calls.

#### Summary
Multiline strings and string interpolation are just great things to have in any language. Its great that you can now use them in your JavaScript (thanks TypeScript!). Tagged templates allow you to create powerful string utilities.
Multiline strings and string interpolation are just great things to have in any language. It's great that you can now use them in your JavaScript (thanks TypeScript!). Tagged templates allow you to create powerful string utilities.

{% include "footer.md" %}
{% include "footer.md" %}