我尝试计算添加数值。例如,
输入:
{i: 10, j: 20}
输出:
30
所以我试试这段代码:
var Sample = function(x,y){
this.a = x;
this.b = y;
}
Sample.prototype.c = 30;
Sample.prototype.totalSum = function (){
return this.a+this.b+this.c
};
var ins1 = new Sample(10,20);
console.log(Object.keys(ins1));
console.log(ins1.totalSum());
其输出:
["a", "b"]
60
但我期待另外两个可能的答案。这(一):
["a", "b", "c"]
60
或这(两):
["a", "b"] // a = 10; b = 20; c = undefined;
NaN
为什么这段代码没有输出这些答案?