@beenotung/tslib
Version:
utils library in Typescript
27 lines (26 loc) • 613 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.bindMethods = bindMethods;
exports.withMethod = withMethod;
/**
* Created by beenotung on 6/21/17.
*/
/**
* fix 'this' scope issue of the member methods when passed to other functions
* @return original object
* */
function bindMethods(o) {
Object.keys(o).forEach(x => {
const f = o[x];
if (typeof f === 'function') {
o[x] = f.bind(o);
}
});
return o;
}
/**
* cast object to class with class methods
* */
function withMethod(c, o) {
return Object.assign(new c(), o);
}