【发布时间】:2012-11-29 13:57:44
【问题描述】:
加载时在 Underscore 上执行代码的正确方法是什么?我正在尝试执行以下代码以在模块需要时自动扩展 _ 导出的命名空间:
_.mixin(_.str.exports());
文档有点含糊,但我想我把它放在了 shim init 部分?我尝试了以下方法,但我什至无法在 init 中找到断点:
require.config({
paths: {
jquery: 'libs/jquery/jquery.min',
underscore: 'libs/underscore/lodash.min',
underscorestring: 'libs/underscore/underscore.string.min'
},
shim: {
underscore: {
exports: '_'
}
underscorestring: {
deps: ['underscore'],
init: function (_) {
//Mixin plugin to namespace
_.mixin(_.str.exports());
return _;
}
}
}
});
当我尝试这样做并使用下划线时,我得到了这个错误:
Uncaught TypeError: Object function s(e){return new o(e)} has no 方法'startsWith'
文档:
【问题讨论】:
标签: javascript asynchronous requirejs underscore.js dynamic-script-loading