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 observable(fn, topic) { | |
function observed() { | |
var result; | |
PubSub.publish(topic + "/before", {obj: this, args: arguments}); | |
result = fn.apply(this, arguments); | |
PubSub.publish(topic + "/after", {obj: this, args: arguments, result: result}); | |
return result; | |
}; | |
observed.before = function (fn) { | |
PubSub.subscribe(topic + "/before", fn); |
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
//http://rmurphey.com/blog/2010/09/15/in-search-of-javascript-developers-a-gist/ | |
// 1: how could you rewrite the following to make it shorter? | |
if (foo) { | |
bar.doSomething(el); | |
} else { | |
bar.doSomethingElse(el); | |
} | |
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
/** | |
* @method curry | |
* @memberOf Function.prototype | |
* @param arg {Any} | |
* @param context {Object} used as /this/ when invoking the original function | |
* @returns {Function} | |
* @example var add1 = (function add(a, b) { return a + b; }).curry(1); | |
* add1(2);//3 | |
* @see http://en.wikipedia.org/wiki/Currying | |
*/ |
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 (global) { | |
var Class = {}; | |
var app = {}; | |
function fluent(obj, fn) { | |
return function () { | |
fn.apply(obj, arguments); | |
return obj; | |
} | |
} |
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
//http://jsperf.com/partial-speed-test | |
var strategy = {}; | |
strategy[1] = function() { | |
var args = Array.prototype.slice.call(arguments); | |
var f = this; | |
return function() { | |
var inner_args = Array.prototype.slice.call(arguments); | |
return f.apply(this, args.concat(inner_args)) | |
}; | |
}; |
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 (global, undef) { | |
/** | |
* memoizes functions with a single, primitive argument | |
* @param f {Function} | |
* @returns {Function} | |
*/ | |
function memoize(f) { | |
var cache = (f.memoize = f.memoize || {}); | |
return function (arg) { | |
return (arg in cache) ? cache[arg] : cache[arg] = f.call(this, arg); |
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 (global) { | |
var cache = {}; | |
function c(n) { | |
if (n < 1) { | |
return new Function; | |
} | |
var i; | |
var params = ""; | |
var vars = " return function () {" + "\n"; |
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(global, undef) { | |
function QueueList(fn, next) { | |
if (!(this instanceof QueueList)) { | |
return new QueueList(fn, next); | |
} | |
this.fn = fn; | |
this.next = next || undef; | |
} | |
QueueList.prototype.after = function(fn) { | |
return new QueueList(fn, 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
(function (global, pubsub, cache) { | |
function push(prop) { | |
return function (val) { | |
this[prop].push(val); | |
return this; | |
}; | |
} | |
function fire(data) { | |
var proceed = true; | |
this.start.every(function (fn) { |
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 (global, known) { | |
global.dev = global.dev || {}; | |
function register(str) { | |
known[str] = str; | |
} | |
function raiseError(leaks) { | |
if (leaks && leaks.length) { | |
throw new Error("global leak" + |