財產「推」我可以在控制檯中調用的,但不是當我按一下按鈕,當一個項目推到價格陣列..遺漏的類型錯誤:無法讀取的不確定
<input type="text" id = "currentPrice">
<button type="button" id = "calcButton">Show</button>
var Newchart = function() {
this.prices = []
}
Newchart.prototype.addNewprice = function() {
var priceValue = +(document.getElementById('currentPrice').value);
this.prices.push(priceValue);
console.log('hello')
}
var c = new Newchart();
var el = document.getElementById("calcButton");
el.addEventListener("click", c.addNewprice, false);
我確定它是重複的。如果有人發現一個好的質量保證,我會關閉。 –
也許https://stackoverflow.com/questions/20279484/how-to-access-the-correct-this-context-inside-a-callback –
@FelixKling這有點太籠統,但它會做。關閉。我讓我的回答集中在這個問題上。 –