UNPKG

@segment/analytics-next

Version:

Analytics Next (aka Analytics 2.0) is the latest version of Segment’s JavaScript SDK - enabling you to send your data to any tool without having to learn, test, or use a new API every time.

20 lines (18 loc) 512 B
export default function bindAll< ObjType extends { [key: string]: any }, KeyType extends keyof ObjType >(obj: ObjType): ObjType { const proto = obj.constructor.prototype for (const key of Object.getOwnPropertyNames(proto)) { if (key !== 'constructor') { const desc = Object.getOwnPropertyDescriptor( obj.constructor.prototype, key ) if (!!desc && typeof desc.value === 'function') { obj[key as KeyType] = obj[key].bind(obj) } } } return obj }