ES6:有没有办法修补导出类的方法?

时间:2020-04-27 15:09:32

标签: javascript ecmascript-6 es6-modules es6-class jupyter-lab

是否有黑客可以通过将更改传播到导入它的每个模块的方式来覆盖导出的类?我正在尝试覆盖从库中导出的方法。被覆盖的更改仅保留在对其进行覆盖的模块中。只是在寻找解决办法吗?

//Module A.js
import { ServerConnection } from '@jupyterlab/services';

ServerConnection.ContentsManager.overrideMethod = fnMyOverrideMethod;
//the above changes are only persisted with the module where it's overriden



 //Module B.js

 import { ServerConnection } from '@jupyterlab/services';

 //ServerConnection.ContentsManager.overrideMethod will not point to the fnMyOverrideMethod

0 个答案:

没有答案