This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Reference: https://github.com/getify/Functional-Light-JS/blob/master/ch3.md#some-now-some-later | |
function partial(fn, ...presetArgs) { | |
return function(...laterArgs) { | |
return fn(...presetArgs, ...laterArgs); | |
}; | |
} | |
// // Or: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<check-list | |
v-model="selected" | |
:options="options" | |
:toggleAllAble="true" | |
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Check if `obj` is a generator. | |
* | |
* @param {Mixed} obj | |
* @return {Boolean} | |
* @api private | |
*/ | |
function isGenerator (obj) { | |
return (typeof obj.next === 'function') && (typeof obj.throw === 'function') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A thing I want to do | |
// This flow only involves **one** promise, for example an ajax call | |
// None of the subsequent `then` or `catch` calls, return new promises. | |
var explode = false; | |
var promise = new Promise(function(resolve, reject) { | |
if (explode) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function configableLogger(format) { | |
var re = /:(\w+)/g; | |
return function(req, res, next) { | |
var str = format.replace(re, (match, property) => { | |
return req[property]; | |
}); | |
console.log(str); | |
next(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arr = [1, 2, 3, 4]; | |
function handleNext(value) { | |
return value * 2 | |
} | |
Array.prototype.fakeMap = function(cb) { | |
return this.reduce((accumulator, next, index) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ruby = 5.times { |i| puts i } | |
// JS = (1).times(function(i){console.log(i);}) | |
Number.prototype.times = function(cb) { | |
var i = -1; | |
while (++i < this) { | |
cb(i); | |
} | |
return +this; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let categories = [ | |
{ id: 'animals', 'parent': null }, | |
{ id: 'mammals', 'parent': 'animals' }, | |
{ id: 'cats', 'parent': 'mammals' }, | |
{ id: 'dogs', 'parent': 'mammals' }, | |
{ id: 'chihuahua', 'parent': 'dogs' }, | |
{ id: 'persian', 'parent': 'cats' }, | |
{ id: 'siamese', 'parent': 'cats' }, | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let o = { | |
*createIterator(items) { | |
for (let i = 0; i < items.length; i++) { | |
yield items[i]; | |
} | |
} | |
}; | |
let it = o.createIterator([1, 2, 3]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function *createIterator(items) { | |
for(let i = 0; i < items.length; i++) { | |
yield items[i]; | |
} | |
} | |
let it = createIterator([1, 2, 3]); | |
console.log(it.next()); // Object {value: 1, done: false} | |
console.log(it.next()); // Object {value: 2, done: false} |