Создайте конструктор, экземпляры которого будут возвращать инкрементированное число
var increment = new Increment();
alert(increment); /* 1 */
alert(increment); /* 2 */
alert(increment + increment); /* 7 */
var Increment = function() { | |
this.int = 0; | |
}; | |
Increment.prototype.toString = function() { | |
return ++this.int; | |
}; | |
var increment = new Increment(); | |
alert(increment); | |
alert(increment); | |
alert(increment + increment); |