@smithery/sdk
Version:
SDK to develop with Smithery
13 lines (12 loc) • 386 B
JavaScript
/**
* Patches a function on an object
* @param obj
* @param key
* @param patcher
*/
// Unified implementation (not type-checked by callers)
export function patch(obj, key, patcher) {
// If the property is actually a function, bind it; otherwise undefined
const original = typeof obj[key] === "function" ? obj[key].bind(obj) : undefined;
obj[key] = patcher(original);
}