Skip to content
New issue

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

a为何止的时候,a==2&&a==3&&a==4 为true? #11

Open
xlearns opened this issue Oct 26, 2021 · 0 comments
Open

a为何止的时候,a==2&&a==3&&a==4 为true? #11

xlearns opened this issue Oct 26, 2021 · 0 comments

Comments

@xlearns
Copy link
Owner

xlearns commented Oct 26, 2021

//方法1
let a = {
  i:1,
  toString:function(){
    return ++this.i
  }
}
console.log(a==2&&a==3&&a==4)
//方法2
let value = 1
Object.defineProperty(window,'a',{
  get:function(){
    return ++value
  }
})
console.log(a==2&&a==3&&a==4)

//方法3
var c = {
  get(obj,key){
    if(key==='a'){
      if(!obj[key]){
        obj[key] = 1
      }
      return ++obj[key]
    }
    return obj[key]
  },
  set(obj,key,val){
    obj[key] = val
  }
}
p = new Proxy(window,c)

console.log(p.a==2&&p.a==3&&p.a==4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant