博客 github 地址: github.com/HCThink/h-b…javascript
github 首頁(star+watch,一手動態直達): github.com/HCThink/h-b…java
原創禁止私自轉載github
注意: 以下代碼可能存在不可見部分: ,若是想看效果,務必 copy 源碼運行, 而不要本身手敲chrome
let a = {
i: 1,
toString: function () {
return a.i++;
}
}
複製代碼
var i = 0;
with({
get a() {
return ++i;
}
}) {
if (a == 1 && a == 2 && a == 3)
console.log("wohoo");
}
// or
Object.defineProperty(window, 'a', {
get: function() {
return ++val;
}
});
// or
window.__defineGetter__( 'a', function(){
if( typeof i !== 'number' ){
// define i in the global namespace so that it's not lost after this function runs
i = 0;
}
return ++i;
});
複製代碼
var a = new Proxy({ i: 0 }, {
get: (target, name) => name === Symbol.toPrimitive ? () => ++target.i : target[name],
});
console.log(a == 1 && a == 2 && a == 3);
複製代碼
// This works because == invokes toString which calls .join for Arrays.
a = [1,2,3];
a.join = a.shift;
console.log(a == 1 && a == 2 && a == 3);
複製代碼
// 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);
複製代碼
var aᅠ = 1;
var a = 2;
var ᅠa = 3;
if(aᅠ ==1 && a == 2 && ᅠa ==3) {
console.log("Why hello there!")
}
// let aᅠ = 1;
// let a = 2;
// let ᅠa = 3;
// https://stackoverflow.com/questions/48270127/can-a-1-a-2-a-3-ever-evaluate-to-true#
// 這裏三個是不一樣的變量,第一個和第三個 a 先後的空白字符不是空格,Unicode FFA0
// 請注意if 語句中的奇怪間距。它是半寬度韓文=,=。這是一個 Unicode 空格字符,可是 ECMAScript 不將其解釋爲一個空格 —— 這意味着它是一個有效的標識符。所以有三個徹底不一樣的變量,一個是a後加半寬度韓文,一個是a, 一個是a前加半寬度韓文。
複製代碼
if=()=>!0;
var i = 1;
if(i == 1 && i == 2 && i == 3)
{
console.log(i)
}
複製代碼
var a = 1;
var ᅠ1 = a;
var ᅠ2 = a;
var ᅠ3 = a;
console.log( a ==ᅠ1 && a ==ᅠ2 && a ==ᅠ3 );
複製代碼