If( a==1 && a==2&&a==3 )는 어떤 상황에서 true와 같습니까?

8709 단어 interviewjavascript

Object.defineProperty()




//Using the principle of data hijacking, ES6 proxy can also be implemented
let bValue = 1;
Object.defineProperty(window, "a", {
  get() { return bValue++; }
});

if(a == 1 && a == 2 && a == 3) {
  console.log("Hello World!");
}


대리




let test = {
  number: 1
};
test = new Proxy(test, {
  get(target, key) {
    return target[key]++;
  }
});
if(test.number === 1 && test.number ===2 && test.number ===3){
    console.log('Hello World!');
}


객체.toString()




let a = [1, 2, 3];
//Use the array method shift to override toString, take the first element of the array and return
a.toString = a.shift;

if (a == 1 && a == 2 && a == 3) {
  console.log("Hello World!");
}

//Override toString method
let a = {
    bValue: 1,
    toString: ()=> {
        return a.bValue++;
    }
}

if (a == 1 && a == 2 && a == 3) {
  console.log("Hello World!");
}


Object.valueOf()




let a = [1, 2, 3];
//Use the array method shift to override valueOf, take the first element of the array and return
a.valueOf = a.shift;

if (a == 1 && a == 2 && a == 3) {
  console.log("Hello World!");
}

/ **
* Override valueOf method
*/

let a = {
    bValue: 1,
    valueOf: ()=> {
        return a.bValue++
    }
};

if (a == 1 && a == 2 && a == 3) {
  console.log("Hello World!");
}

좋은 웹페이지 즐겨찾기