Skip to content

Instantly share code, notes, and snippets.

@bonkydog
Created November 6, 2009 06:21
Show Gist options
  • Save bonkydog/227770 to your computer and use it in GitHub Desktop.
Save bonkydog/227770 to your computer and use it in GitHub Desktop.
// Douglas Crockford-fu from JavaScript: The Good Parts
// http://oreilly.com/catalog/9780596517748/
Function.prototype.method = function (name, func) {
this.prototype[name] = func;
return this;
};
if (typeof Object.create !== ' function') {
Object.create = function (o) {
var F = function () {
};
F.prototype = o;
return new F();
};
}
Function.method('curry', function ( ) {
var slice = Array.prototype.slice,
args = slice.apply(arguments),
that = this;
return function ( ) {
return that.apply(null, args.concat(slice.apply(arguments)));
};
});
var constructor = function (spec, my) {
var that, other private instance variables;
my = my || {};
Add shared variables and functions to my
that = a new object;
Add privileged methods to that
return that;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment