ComfyUI/web/scripts/utils.js
2023-08-23 10:32:40 -05:00

24 lines
440 B
JavaScript

export function range(size, startAt = 0) {
return [...Array(size).keys()].map(i => i + startAt);
}
export function hook(klass, fnName, cb) {
const fnLocation = klass;
const orig = fnLocation[fnName];
fnLocation[fnName] = (...args) => {
cb(orig, ...args);
}
}
const a = {
b: (c, d, e) => {
console.log(c, d, e);
}
}
a.b(1,2,3)
hook(a, "b", (orig, c, d, e) => {
orig(c, d, e);
})
a.b(1,2,3)