fix: this binding

Co-authored-by: Su-Yong <simssy2205@gmail.com>
This commit is contained in:
JellyBrick
2023-11-28 01:39:11 +09:00
parent d84416b27c
commit 3152842a30
2 changed files with 12 additions and 3 deletions

View File

@ -41,6 +41,15 @@ export const startPlugin = <Config extends PluginConfig>(id: string, def: Plugin
if (!lifecycle) return false;
try {
const defContext = def[options.ctx];
if (defContext && typeof defContext !== 'function') {
Object.entries(defContext)
.forEach(([key, value]) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
if (typeof value === 'function') defContext[key as keyof typeof defContext] = value.bind(defContext);
});
}
const start = performance.now();
lifecycle.bind(def[options.ctx])(options.context as Config & typeof options.context);