I was trying to understand JavaScript Promises by using various libraries (bluebird, when, Q) and other async approaches.
I read the spec, some blog posts, and looked through some code. I learned how to
| const { assert } = require('chai'); | |
| function isError(e) { | |
| if (typeof e === 'string') { | |
| return Promise.reject(new Error(e)); | |
| } | |
| return Promise.resolve(e); | |
| } |
| // Declare/initialize any useful variables here, including the temporary array | |
| // to merge values into and then copy back into the parameter array. | |
| /* | |
| while the temporary array is not filled | |
| if there are no more values in the left part of a, | |
| move next value from right part of a into next index of the temporary array otherwise, if there are no more values in the right part of a, | |
| move next value from left part of a into next index of the temporary array otherwise (values in each part) compare the first value in each part | |
| move smallest value from a into next index of the temporary array |
I was trying to understand JavaScript Promises by using various libraries (bluebird, when, Q) and other async approaches.
I read the spec, some blog posts, and looked through some code. I learned how to
| // from google javascript style guide: | |
| // One thing to keep in mind, however, is that a closure keeps a pointer to its enclosing scope. As a | |
| // result, attaching a closure to a DOM element can create a circular reference and thus, a memory leak. | |
| // For example, in the following code: | |
| // Leaky example | |
| function foo (element, a, b) { | |
| element.onclick = function() { | |
| // uses a and b | |
| // this func keeps a pointer to foo, its enclosing scope |