我尝试使用如下定义的 3 个差异模块
信用.js
define(function(){
return{
getCredits: function (){
console.log("Inside getCredits");
return 10;
}
}
});
产品.js
define(function(){
console.log("Inside product");
return {
bookTheProduct: function(){
console.log("Inside bookTheProduct");
return true;
}
}
});
购买.js
require.config({
shim: {
purchase: {
deps : ["credit","product"]
}
}
});
define(["credit","product"], function(credit,product){
console.log("purchaseproduct");
return {
purchaseProduct: function (){
console.log("Inside of PurchaseProduct");
var credits = credit.getCredits();
if(credits > 0){
product.bookTheProduct();
return true;
}
return false;
}
}
});
在 app.js 中使用它
require(["purchase"],function(purchase){
purchase.purchaseProduct();
})
在 Firefox 21.0 中尝试过,在加载购买时加载信用模块但从未加载产品模块。如果我颠倒顺序,它会加载产品模块而不是信用模块。在 RequireJs 文档和 mozilla 文档中都没有找到任何帮助。也没有看到有人抄袭它。有没有人遇到过这个问题?我做错了什么,如果可以,请指出错误。谢谢