,我在下面的教程:要求JS与underscore.js不工作
http://javascriptplayground.com/blog/2012/07/requirejs-amd-tutorial-introduction
我基本上做的是需要“jQuery的”和“强调”
下面是一个简单的模板模块我app.js
require.config({
paths: {
"jquery": "https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min",
"underscore": "http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.3/underscore-min"
}
});
require(['template'], function(template) {
//Template is undefined
console.log(template);
});
这里是我的template.js
define(['underscore', 'jquery'], function()
{
var showName = function(n)
{
var temp = _.template("Hello <%= name %>");
$("body").html(temp({name: n}));
};
return
{
showName: showName
};
});
我已验证所有脚本都通过谷歌浏览器的网络标签拉入,但模板回调没有定义。
编辑: 看来,错误是由在另一行返回{
引起的。我从来没有遇到过这与JavaScript ...有没有这样的规则?