(A == 3 && a == 4 && a == 5) the return of true

 

1. Object.defineProperty

 
var val = 1;
Object.defineProperty(window, 'a', { configurable: true, get: function() { console.log(`触发第${val}次get`); return val++ } }) if(a == 1 && a == 2 && a == 3) { console.log('yes!') } 触发第1次get 触发第2次get 触发第3次get yes! 

2. toString() valueOf()

const b = {
  i: 1,
  toString: function () { return this.i++; } } if(b == 1 && b == 2 && b == 3) { console.log('Hello World!'); // Hello World! } const b = { i: 1, valueOf: function () { return this.i++; } } if(b == 1 && b == 2 && b == 3) { console.log('Hello World!'); // Hello World! } 
Compare implicitly calls toString or valueOf method, if the original value and the type of object comparison, the object will be converted values ​​of the original type, and then compared. Object value converted into original type, the algorithm is the first call valueOf method, if the object is returned, then calls again toString method

3. array.join = array.shift

var a = [1,2,3];
a.join = a.shift;
console.log(a == 1 && a == 2 && a == 3);

a == 1 ,此时 a 返回的就是shift返回的第一个元素 1 ,比较完之后  a = [2,3]
a == 2 ,此时 a 返回的就是shift返回的第一个元素 2 ,比较完之后  a = [3]
a == 3 ,此时 a 返回的就是shift返回的第一个元素 3 ,比较完之后  a = []
Arrays are objects, the array toString method returns a string from the toString each element in the array () Returns the value by calling join () method connector (separated by a comma) components.

4.Proxy

var a = new Proxy({ i: 0 }, {
 
get: (target, name) => name === Symbol.toPrimitive ? () => ++target.i : target[name],
 
});
 
console.log(a == 1 && a == 2 && a == 3);

 

5. Symbol.toPrimitive

// Another solution, using Symbol.toPrimitive which is an ES6 equivalent of toString/valueOf
let a = {[Symbol.toPrimitive]: ((i) => () => ++i) (0)};
 
console.log(a == 1 && a == 2 && a == 3);

 

6. Special Assignment

var A = ㅤ. 1 ;
 var A = 2 ;
 var ㅤ A =. 3 ;
 IF (A ㅤ. 1 && A == == == 2 && A ㅤ. 3 ) { 
    the console.log ( "Why there Hello!" ) 
} 
 
/ / the let A = ㅤ. 1; 
// the let A = 2; 
// the let A = ㅤ. 3; 
// https://stackoverflow.com/questions/48270127/can-a-1-a-2-a-3- -to-the evaluate-Ever # to true 
// here are three different variables, the first and third whitespace characters before and after a not a space, Unicode FFA0 
// Note that if the statement of strange spacing. It is the half-width Korean =, =. This is a Unicode space character, but ECMAScript not be interpreted as a single space - which means it is a valid identifier. Thus there are three completely different variables, a half width is added after a Korean, a is a, a half width is preceded by a Korean.

7. Digital variable name

var   a = 1 ;
var ㅤ 1 = a;
var ㅤ 2 = a;
var ㅤ = 3 ares; 
console.log (a == 1 && a ㅤ ㅤ == == 2 && a ㅤ 3);

 

If you have other methods to achieve, you can leave your comments on the implementation yo!

 

Guess you like

Origin www.cnblogs.com/wangking/p/11202572.html