alert(nf); // 5
为什么alert弹出的是5呢?
而console.log(nf); 却是numCount
我把numCount.prototype.toString改成numCount.prototype.toString1
alert就弹出[object Object]..
这是什么原因啊?
function numCount(){
var answer = 0;
}
numCount.prototype.addNumbers = function(num1,num2){
this.answer = num1 + num2;
}
numCount.prototype.toString2 = function(){
return this.answer;
}
var nf = new numCount();
nf.addNumbers(2,3);
console.log(nf); // numCount
alert(nf); // 5
为什么alert弹出的是5呢?
而console.log(nf); 却是numCount
我把numCount.prototype.toString改成numCount.prototype.toString1
alert就弹出[object Object]..
这是什么原因啊?
function numCount(){
var answer = 0;
}
numCount.prototype.addNumbers = function(num1,num2){
this.answer = num1 + num2;
}
numCount.prototype.toString2 = function(){
return this.answer;
}
var nf = new numCount();
nf.addNumbers(2,3);
console.log(nf); // numCount
alert(nf); // 5
alert弹出的是5?
所以是toString2