We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
如题
https://mp.weixin.qq.com/s/OBb0zrfGAI6w4ILvT5T5-A
The text was updated successfully, but these errors were encountered:
方法一: 利用隐式转换会调用 valueOf
const a = { value: 1, valueOf() { return this.value++ } }; console.log(a == 1 && a == 2 && a == 3) // true
Sorry, something went wrong.
方案二: 在对象 valueOf 函数不存在的情况下会调用 toString 方法
toString
const a = { value: 1, toString() { return this.value++; } }; console.log(a == 1 && a == 2 && a == 3) // true
方案三: 利用 Object.defineProperty 在全局 window 上挂载一个 a 属性
Object.defineProperty
window
let _a = 1 Object.defineProperty(window, 'a', { get() { return _a++ } }); console.log(a == 1 && a == 2 && a == 3)
No branches or pull requests
如题
https://mp.weixin.qq.com/s/OBb0zrfGAI6w4ILvT5T5-A
The text was updated successfully, but these errors were encountered: