UNPKG

bind-methods

Version:

Bind all methods in an object to itself or a specified context

12 lines (9 loc) 241 B
export default function bindMethods(object, context) { context = context || object; for (const [key, value] of Object.entries(object)) { if (typeof value === 'function') { object[key] = value.bind(context); } } return object; }