Created
April 14, 2009 19:36
-
-
Save appden/95379 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
Class.Mutators.BindAll = function(self, bool) { | |
if (!bool) return self; | |
var init = self.initialize; | |
var exclude = arguments.callee.exclude; | |
self.initialize = function() { | |
for (var method in this) { | |
if (typeof this[method] != 'function' || exclude.contains(method)) | |
continue; | |
var unbound = this[method]; | |
this[method] = unbound.bind(this); | |
this[method].__parent = unbound.__parent; | |
} | |
return init ? init.apply(this, arguments) : this; | |
}; | |
return self; | |
}; | |
Class.Mutators.BindAll.exclude = ['constructor', 'initialize', 'parent']; | |
/* | |
Please see for more info: | |
http://appden.com/javascript/bindall-class-mutator-for-saving-your-sanity/ | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment