@anywhichway/nerd-editor
Version:
A JavaScript rich text editor based on and with support for custom elements.
15 lines (13 loc) • 425 B
JavaScript
// binds an object's methods so that they still have this scope when destructured
const bind = (object,scope,direct) => {
const target = direct ? object : Object.assign({},object);
scope ||= target;
for(const key in target) {
const value = target[key];
if(typeof(value)==="function") {
target[key] = value.bind(scope);
}
}
return target;
}
export {bind}