-
Expressive They say something about the purpose and result of the iteration.
-
Contained They don't have side effects if used properly. All relevant stuff occurs within the callback.
-
Scoped They provide automatic function scope for each iteration which eliminates a common type of error.
This file contains hidden or 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 curry = (fn, ...args) => args.length >= fn.length ? fn(...args) : (...more) => curry(fn, ...args, ...more) | |
// just to make the gist longer. |
This file contains hidden or 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
[..., last] = arr |
This file contains hidden or 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 Bluebird = require("bluebird"); | |
var nba = require("nba"); | |
Object.keys(nba.api).forEach(function (method) { | |
var original = nba.api[method]; | |
nba.api[method] = Promise.promisify(original); | |
}); |
This file contains hidden or 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 helloProto = { | |
toString: function () { | |
return "Hello!"; | |
} | |
} | |
function helloFactory () { | |
return Object.create(helloProto); | |
} |
This file contains hidden or 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
/** | |
* Enable route to __noSuchMethod__ when unknown method calling. | |
* | |
* @param {Object} obj Target object. | |
* @return {Object} | |
*/ | |
function enableMethodMissing(obj) { | |
var functionHandler = createBaseHandler({}); | |
functionHandler.get = function(receiver, name) { |
This file contains hidden or 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 grabIt (thing) { | |
var frame = document.createElement('iframe'); | |
document.body.appendChild(frame); | |
var thing = frame.contentWindow[thing]; | |
document.body.removeChild(frame); | |
return thing; | |
} | |
var Collection = grabIt("Array"); |
This file contains hidden or 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 Benchmark = require( 'benchmark' ); | |
var len = process.argv[2] || 3; | |
var obj = {}; | |
for ( var i = 0; i < len; i++ ) { | |
obj[i] = "value" + i; | |
} |
This file contains hidden or 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 Singleton = (function() { | |
var instance; | |
return function () { | |
if ( !this instanceof Singleton ) { | |
return new Singleton(); | |
} | |
if ( !instance ) { | |
instance = this; | |
} | |
return instance; |
This file contains hidden or 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 applyConstructor ( ctor, args ) { | |
var instance; | |
function C () {} | |
C.prototype = ctor.prototype; | |
var instance = new C(); | |
ctor.apply( instance, args ); | |
return instance; | |
} |