Created
November 6, 2009 06:21
-
-
Save bonkydog/227770 to your computer and use it in GitHub Desktop.
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
// 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