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 formatValue(x) { | |
var ret; | |
if (typeof x == "string") { | |
return "'" + x.replace(/\n/g,"\\n") + "'"; | |
} | |
if (typeof x == "number" && x === 0 && (1/x === -Infinity)) { | |
return "-0"; | |
} | |
if (Array.isArray(x)) { |
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
// because of declaration hoisting, wherever we put `filter()`, it | |
// will be declared for a longer lifetime than is necessary. | |
// | |
// inline function expression (or arrow function) inside the loop | |
// isn't the answer, because then you recreate the function over | |
// and over again. | |
function doSomething() { | |
var items = [], i, ret = 0; | |
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
/*global setTimeout */ | |
var Queue = function Queue(q) { | |
"use strict"; | |
// (C) WebReflection - Mit Style License | |
var callback, | |
next = function next() { | |
callback = q.shift(); | |
if (callback) { callback(q); } | |
return !!callback; | |
}; |
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 EventEmitter = require("events").EventEmitter; | |
var emitter = new EventEmitter(); | |
var foo = function () { | |
console.log("foo"); | |
}; | |
emitter.once("foo", foo); | |
var bar = 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
Function.prototype.within = function (millis) { | |
var that = this; | |
return function () { | |
var args = Array.prototype.slice.call(arguments); // if sinful present, slice(arguments) | |
return window.setTimeout(function () { that.apply(null, args); }, millis); ); | |
}; | |
}; |