Created
October 23, 2013 15:51
-
-
Save bitoiu/7121245 to your computer and use it in GitHub Desktop.
d3js rebind playground
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 rebind(target, source) { | |
var i = 1, n = arguments.length, method | |
hile (++i < n) target[method = arguments[i]] = innerRebind(target, source, source[method]) | |
return target | |
} | |
function innerRebind(target, source, method) { | |
return function() { | |
if ( isFunctionA(source[method])) { | |
var value = method.apply(source, arguments); | |
return value === source ? target : value; | |
} | |
return source[method] | |
} | |
} | |
function isFunction(object) { | |
return object && getClass.call(object) == '[object Function]'; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment