Skip to content

Commit

Permalink
final tweaks to request a PR
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaxolotl committed Sep 20, 2019
1 parent 945958f commit 1f73346
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
19 changes: 7 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,18 @@ A lot of information has been written about JavaScript and EcmaScript since both
- Exercises
- DAY 7
- `this` Keyword
- <https://github.com/getify/You-Dont-Know-JS/blob/master/this%20%26%20object%20prototypes/ch1.md>
- <https://github.com/getify/You-Dont-Know-JS/blob/master/this%20%26%20object%20prototypes/ch2.md>
- <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this>
- BIND
- APPLY
- CALL
- Introduction
- Resolving `this`
- Explicitly binding `this` through prototype methods
- `Function.prototype.bind()`
- `Function.prototype.apply()`
- `Function.prototype.call()`
- Strict mode
- What happens on strict mode?
- Semantic Differences
- Arrow Functions
- ...
- ...
- .. good practices
- Generators
- ..
- ..
- .. good practices
- Exercises
- DAY 8
- Classes
- <https://www.ecma-international.org/ecma-262/6.0/#sec-class-definitions>
Expand Down
32 changes: 30 additions & 2 deletions day_07.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ f(); // 6

```

One of the most expected and misused features of ES6 is the Arrow Function. Undoubtedly powerful it might also derive in a headache inf you don't really know how they work and which are the difference between the full body notation and the arrow notation.
One of the most expected and misused features of ES6 is the Arrow Function. Undoubtedly powerful it might also derive in a headache if you don't really know how they work and which are the difference between the full body notation and the arrow notation.

Let's take a look at [YDKJS - ES6 & Beyond - chapter 2](https://github.com/getify/You-Dont-Know-JS/blob/1st-ed/es6%20%26%20beyond/ch2.md#arrow-functions)

Expand Down Expand Up @@ -196,6 +196,7 @@ Since this is a particularly complex topic, with several nuances, let's try to u
/**
*
* @param {number} initialValue
* @returns {Object} Generator
*/
function* bottlesOfBeer (initialValue) {
let bob = initialValue;
Expand Down Expand Up @@ -245,6 +246,7 @@ bob.next();
```javascript
/**
*
* @returns {Object} Generator
*/
function* passingValToNext () {
let val = 10;
Expand All @@ -257,6 +259,22 @@ function* passingValToNext () {
console.log(`DOWN val=${val}`);
}
}

let pvtn = passingValToNext();
// statement completion value -> passingValToNext {<suspended>}

pvtn.next(2);
// log -> UP val=10
// statement completion value -> {value: 20, done: false}

pvtn.next(7);
// log -> DOWN val=7
// log -> UP val=7
// statement completion value -> {value: 17, done: false}

// WAIT! WHAT??!!!!
// how does it work?

```

### Sample combining initial value and passing value to next
Expand All @@ -265,7 +283,7 @@ function* passingValToNext () {
/**
*
* @param {Number} expectedTotal
* @returns {Object} Iterator
* @returns {Object} Generator
*/
function* calculateDownloadProgress (expectedTotal) {
let totalDownloaded = 0;
Expand All @@ -279,13 +297,23 @@ function* calculateDownloadProgress (expectedTotal) {
newItems = yield `${percent}%`;
}
}

let progress = calculateDownloadProgress(1024);
// statement completion value -> undefined
progress.next()
// statement completion value -> {value: "0.00%", done: false}
progress.next(15)
// statement completion value -> {value: "1.46%", done: false}
progress.next(500)
// statement completion value -> {value: "50.29%", done: false}
```

### DIY

```javascript
/**
*
* @returns {Object} Generator
*/
function* spinGen() {
while(true){
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "a-walk-in-javascript",
"version": "1.2.0",
"version": "1.3.0",
"description": "A day by day walk through the basics of javascript assisted with notes, exercises and references to the most significant resources online",
"main": "''",
"scripts": {
Expand Down

0 comments on commit 1f73346

Please sign in to comment.