var increment = new Increment()
console.log('val: ' + increment) // val: 1
console.log('val: ' + increment) // val: 2
console.log('val: ' + increment) // val: 3
class Increment {
constructor() {
this.count = 1;
}
valueOf() {
return this.count++;
}
}
function Increment() {
this.count = 1;
}
Increment.prototype.valueOf = function() {
return this.count++;
}