I have the following code in a file called 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());
But when I run it using node as follows, I get the following output node index.js :
undefined
undefined
What am I doing wrong?
You have a typo;
Answer.prototype.get = function get() {
return this._value; // this line should be: return this._val;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.