@d3fc/d3fc-rebind
Version:
Utilities for copying methods from one d3 component to another in a configurable way
11 lines (10 loc) • 354 B
JavaScript
export default (target, source, name) => {
const method = source[name];
if (typeof method !== 'function') {
throw new Error(`Attempt to rebind ${name} which isn't a function on the source object`);
}
return (...args) => {
var value = method.apply(source, args);
return value === source ? target : value;
};
};