@bbc/http-transport
Version:
A flexible, modular REST client built for ease-of-use and resilience.
16 lines (13 loc) • 418 B
JavaScript
;
function isMethod(propertyName, value) {
return propertyName !== 'constructor' && typeof value === 'function';
}
module.exports = (obj) => {
const propertyNames = Object.getOwnPropertyNames(obj.constructor.prototype);
propertyNames.forEach((propertyName) => {
const value = obj[propertyName];
if (isMethod(propertyName, value)) {
obj[propertyName] = value.bind(obj);
}
});
};