我想从子模块传递参数给父模块构造函数,但由于某些原因参数未传递给父项。参数不会从子项传递给父项
这是孩子模块:
var Child = (function()
{
/**
* @constructor
*/
var Child = function(offer)
{
_Parent.call(this, offer);
};
/**
* Prototype.
*/
Child.prototype = Object.create(_Parent.prototype);
Child.prototype.construct = Child;
return Child;
}());
而下面是父:
var _Parent = (function()
{
/**
* Contains the offer data.
*
* @type {{}}
*/
var offerData = {};
/**
* @construct
*/
var _Parent = function(offer)
{
offerData = offer;
};
/**
* Get the offer price.
*
* @param offering Index of the offering of which the price should be returned.
*/
var getPrice = function(offering)
{
if(typeof offering == 'undefined')
{
offering = 0;
}
return offerData[offering]['Prices']['PriceRow']['TotalPriceInclVAT'];
};
/**
* Prototype.
*/
_Parent.prototype = {
construct : _Parent,
getPrice : getPrice
};
return _Parent;
}());
我试图在getPrice()
功能上的孩子是这样的:
var child = new Child(offers);
child.getPrice();
但我总是收到Uncaught TypeError: Cannot read property 'undefined' of undefined
里面的getPri每当我尝试返回数据时,都会使用函数。
你确定'offer'不是'undefined'吗? – Joseph
我认为你得到的错误是'Uncaught TypeError:无法读取未定义的属性'原型'。这是我复制代码时得到的结果。 –
@JosephtheDreamer刚刚重新检查,我可以确认设置了“offers”。 – siannone