我想从require()函数的成功侦听器中访问foo.settings.debug对象。我不断收到一个未定义的错误,当我引用“this”时,它最终引用了 ajax 对象。请协助。
var foo = {
info: {
version: '0.0.1'
},
settings: {
debug: true
},
require: function(script) {
$.ajax({
url: script,
dataType: "script",
async: false,
success: function(){
if(foo.settings.debug) console.log('loaded js file: ' + script);
},
error: function(){
throw new Error("Could not load script " + script);
}
});
}
}