我需要創建一個構造函數,以提醒increament價值,如何做到這一點?增量的JavaScript
這是我
var increment = new Increment();
alert(increment); /* 1 */
alert(increment); /* 2 */
alert(increment + increment); /* 7 */
我需要創建一個構造函數,以提醒increament價值,如何做到這一點?增量的JavaScript
這是我
var increment = new Increment();
alert(increment); /* 1 */
alert(increment); /* 2 */
alert(increment + increment); /* 7 */
輕鬆!
function Increment(){
this.i = 0;
}
Increment.prototype.toString = function(){
this.i++;
return this.i;
}
var increment = new Increment();
但是........爲什麼! – adeneo 2015-04-06 11:22:00
另外,不能做!在你的代碼'increment'只是一個參考,它不能增加whitout叫什麼 – adeneo 2015-04-06 11:22:55