Skip to content

Instantly share code, notes, and snippets.

@bitoiu
Created October 23, 2013 15:51
Show Gist options
  • Save bitoiu/7121245 to your computer and use it in GitHub Desktop.
Save bitoiu/7121245 to your computer and use it in GitHub Desktop.
d3js rebind playground
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