示例工程 10-amd-requirejs
10-amd-requirejs/02-paths-shim/amd/use-legacy.js
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
// amd/use-legacy.js —— 把 shim 包装后的全局构造函数当模块依赖使用
define(['legacy'], function (LegacyCounter) {
return {
demo: function () {
var counter = new LegacyCounter();
counter.inc();
counter.inc();
return counter.n;
}
};
});