条件:
1)我们有一堆使用以下模式的遗留代码:
base.js
var Base = function(config) {
var that={};
that.doThing1=function(){};
that.doThing2=function(){};
return that;
}
child.js
var Child = function(config) {
var that=Base;
that.doStuff1=function(){that.doThing1();};
that.doThing2=function(){};
return that;
}
2)最重要的事情之一是它是遗留代码,而且很多,所以重构一切以使用不同的模式现在完全不可能。
3)我正在尝试将 require.js 用于当前项目,以及 w/backbone,因此我想要在其中需要“Base”依赖项的子类。
这是我现在所在的位置,但它不起作用:
require('Base'), function(Base) {
var Child = function(config) {
var that=Base;
that.doStuff1=function(){that.doThing1();};
that.doThing2=function(){};
return that;
}
return Child;
}
问题):
如何设置此模式,以便我可以将 require() 包裹在它周围,以异步获取遗留依赖项,以便我可以将 require() Child 放入主干类?