1.求a的值 ,什么情况下能满足这个条件表达式
let a = ?
if (a == 1 && a == 2 && a == 3) {
console.log(1)
}
答案:
let a = {
i: 0,
toString() {
return ++this.i
}
}
原理参考:https://blog.csdn.net/qq_42833001/article/details/83302149
Object.defineProperty与Proxy理解整理
let i = 0
Object.defineProperty(window, 'a', {
get() {
return ++i
}
})
if (a == 1 && a == 2 && a == 3) {
console.log(1)
}
第三种 :
var a = [1, 2, 3]
a.toString = a.shift