Below is the Javascript object that I have:
var calc = {
title : 'Calculator',
plus : function( a, b ) {
return (
console.log(this), // calc
console.log(arguments), // [ 3, 5 ]
console.log(a+b), // 8
console.log(this.title) // Calculator
)
}
};
And I am trying to access the prototype of this object calc
by the following:
calc.prototype.getNum = function( numStr ) {
return isNaN(parseInt(numStr)) ? 'Not a valid number!' : parseInt(numStr);
};
But it keeps giving the following error, whenever I execute it!
TypeError: Cannot set property 'getNum' of undefined
Can anyone please tell me what I'm doing wrong here?