![](/img/trans.png)
[英]Only the first answer of an array of objects returning true in a trivia game, rather than the correct answer in Javascript
[英]node is not returning the correct answer
我在名為index.js的文件中包含以下代碼
function Answer(value) {
this._val = value;
}
Answer.prototype.get = function get() {
return this._value;
}
var lifeAnswer = new Answer(42);
console.log(lifeAnswer.get());
var piAnswer = new Answer(3.14159);
console.log(piAnswer.get());
但是當我使用node如下運行它時,我得到了以下輸出節點index.js:
undefined
undefined
我究竟做錯了什么?
你有錯字;
Answer.prototype.get = function get() {
return this._value; // this line should be: return this._val;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.