「方案1」
利用转换规则:object与数字比较, 调用object的valueOf方法;
var a = {
value: 1,
valueOf: function(){
return this.value++;
}
}
console.log(a == 1 && a == 2 && a == 3)
「方案二」利用getter存储器
var temp = 1;
Object.defineProperty(window, 'a', {
get: function(){
return this.temp++;
}
})