我有两个实例,cartParent和ShowCart;我想从cartParent访问showCart,但是我无法从cartParent代码内部获取showCart.addItemToShow(obj),它返回undefined,这是我的代码:>
var cartParent=(function(addTocart,showCart,Product){
var total=0;
return{
totalCalc:function(qty){
$.get("../products.txt",function(data,status,xhr)
{
if(status=="success"){
console.log(JSON.parse(data));
$.each(JSON.parse(data), function(i, e){
if(e.id==id){
console.log(e.id);
var price=e.price;
var name=e.name;
var desc=e.desc;
var img=e.img;
var obj= item(id,name,price,qty);
showCart.addItemToShow(obj);
}
})
}
})
}
}
})(addTocart,showCart,Product);
var showCart=(function(){
return{
addItemToShow:function(obj){
console.log("obj:"+obj.price)
}
}
})();