我开始学习 YepNope 并有这样的脚本:
yepnope([
{
load: 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js',
},
{
test: true,
yep: {
'jquery-ui' : 'js/jquery-ui.js',
'jquery-expandable' : 'js/jquery.expandable.js',
'triggers' : 'js/triggers.js',
'prettify' : 'js/prettify/prettify.js'
},
callback: {
'prettify': function (url, result, key) {
console.log(key + ' loaded ' + result);
prettyPrint();
}
}
}
]);
我只需要一个回调来美化。然而,运行上述显示控制台日志已成功加载,但 prettyPrint() 未定义。
如果我为其他键设置空白函数回调,例如:
yepnope([
{
load: 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js',
},
{
test: true,
yep: {
'jquery-ui' : 'js/jquery-ui.js',
'jquery-expandable' : 'js/jquery.expandable.js',
'triggers' : 'js/triggers.js',
'prettify' : 'js/prettify/prettify.js'
},
callback: {
'jquery-ui': function(url, result, key) {
},
'jquery-expandable': function(url, result, key) {
},
'triggers': function (url, result, key) {
},
'prettify': function (url, result, key) {
console.log(key + ' loaded ' + result);
prettyPrint();
}
}
}
]);
这确实有效。那么当使用这种语法时,我们是否必须为每个回调指定一个键,即使我们不需要特定键的回调?或者这是 YepNope 中的一个错误?我也可以在 Modernizr.load 版本的脚本中重现这一点。