我想從子模塊傳遞參數給父模塊構造函數,但由於某些原因參數未傳遞給父項。參數不會從子項傳遞給父項
這是孩子模塊:
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