简体   繁体   English

有谁知道 Javascript 中的 this 是什么意思? `ǀǀ+(ǀ==ǀ-->ǀ+ǀ<--ǀ==ǀ)+ǀǀ`

[英]Does anyone know what this in Javascript means? `ǀǀ+(ǀ==ǀ-->ǀ+ǀ<--ǀ==ǀ)+ǀǀ`

So I was looking at someones code on a website and while looking around, I saw this:所以我在网站上查看某人的代码,环顾四周,我看到了:

 var ǀ = 1; var ǀǀ = 21; var s = ǀǀ+(ǀ==ǀ-->ǀ+ǀ<--ǀ==ǀ)+ǀǀ; document.writeln(s);

This somehow equates to 42?这在某种程度上等于 42? Does anyone know how they are doing this?有谁知道他们是如何做到这一点的? I thought ||我以为|| and |和| where for or ?在哪里or

They're (ab)using a character that looks a whole lot like a vertical bar ( | ) such as what's used in "or" ( || ).他们(ab)使用了一个看起来很像竖线( | )的字符,例如“或”( || )中使用的字符。

You could rewrite their code like this:你可以像这样重写他们的代码:

 var a = 1; var b = 21; var s = b + (a == a-- > a + a < --a == a) + b; document.writeln(s);

or further simplified:或进一步简化:

 var s = 21 + (1 == 1 > 0 + 0 < -1 == -1) + 21; document.writeln(s); // Even further simplified var s = 21 + (true > false < true) + 21; document.writeln(s); // Clean up that middle case var s = 21 + (false) + 21; document.writeln(s); // Coerce to a number var s = 21 + 0 + 21; document.writeln(s); // Last simplification var s = 21 + 21; document.writeln(s);

No special operators.没有特殊的运算符。 Just normal ones smushed together with odd-looking variable names.只是普通的与奇怪的变量名称混在一起。

ǀ and ǀǀ are (Unicode) variable names. ǀǀǀ是 (Unicode) 变量名。

Space it out:把它隔开:

var ǀ = 1;
var ǀǀ = 21;
var s = ǀǀ + (ǀ == ǀ-- > ǀ + ǀ < --ǀ == ǀ) + ǀǀ;

Apply operator precedence and associativity:应用运算符优先级和结合性:

var ǀ = 1;
var ǀǀ = 21;
var s = (ǀǀ + ((ǀ == ((ǀ-- > (ǀ + ǀ)) < --ǀ)) == ǀ)) + ǀǀ;

Apply order of evaluation:应用评估顺序:

var a = ǀǀ + ((ǀ == ((ǀ-- > (ǀ + ǀ)) < --ǀ)) == ǀ);
var s = a + ǀǀ;
var b = (ǀ == ((ǀ-- > (ǀ + ǀ)) < --ǀ)) == ǀ;
var a = ǀǀ + b;
var c = ǀ == ((ǀ-- > (ǀ + ǀ)) < --ǀ);
var b = c == ǀ;
var d = (ǀ-- > (ǀ + ǀ)) < --ǀ;
var c = ǀ == d;
var e = ǀ-- > (ǀ + ǀ);
var d = e < --ǀ;
var g = ǀ--;
var f = ǀ + ǀ;
var e = g > f;

Evaluate:评估:

var ǀ = 1;
var ǀǀ = 21;

var g = ǀ--;
var f = ǀ + ǀ;
var e = g > f;
var d = e < --ǀ;
var c = ǀ == d;
var b = c == ǀ;
var a = ǀǀ + b;
var s = a + ǀǀ;
var ǀ = 0;
var ǀǀ = 21;

var g = 1;
var f = ǀ + ǀ;
var ǀ = 0;
var ǀǀ = 21;

var f = 0 + 0;
var e = g > f;
var ǀ = 0;
var ǀǀ = 21;

var e = 1 > 0;  // true
var d = e < --ǀ;
var ǀ = -1;
var ǀǀ = 21;

var d = true < -1;  // false
var c = ǀ == d;
var ǀ = -1;
var ǀǀ = 21;

var c = -1 == -1;  // true
var b = c == ǀ;
var ǀ = -1;
var ǀǀ = 21;

var b = true == -1;  // false
var a = ǀǀ + b;
var ǀ = -1;
var ǀǀ = 21;

var a = 21 + false;  // 21
var s = a + ǀǀ;
var ǀ = -1;
var ǀǀ = 21;

var s = 21 + 21;  // 42

It is a joke (a bad one).这是一个笑话(一个坏的)。 It isn't an operator.它不是运营商。 It is a collection of variable and operators put together to look intentionally confusing.它是一组变量和运算符放在一起看起来故意混淆。

It is taking advantage of the visual similarities between ǀ (U+01C0 : LATIN LETTER DENTAL CLICK {pipe}) which is a character you can use in a variable name and |它利用了ǀ (U+01C0 : LATIN LETTER DENTAL CLICK {pipe}) 之间的视觉相似性,这是一个可以在变量名中使用的字符和| (U+007C : VERTICAL LINE {vertical bar}) which is an operator. (U+007C : VERTICAL LINE {vertical bar}) 这是一个运算符。

This is a mixture of obfuscation, and some abuse of weak typing.这是混淆和一些弱类型滥用的混合体。

First, ǀ and ǀǀ here are just variables with funny names - names that look a bit like, but aren't actually, the common character |首先,这里的ǀǀǀ只是名称很有趣的变量 - 名称看起来有点像,但实际上并不是常见的字符| , which would be an operator. ,这是一个运算符。 So let's swap them out:所以让我们换掉它们:

var a = 1;
var b = 21;
var s = b+(a==a-->a+a<--a==a)+b;
document.writeln(s);

Now we have various operations on one line, we need to work out the precedence of the different operators , so we can break it down in the right order.现在我们在一行上有各种操作,我们需要计算出不同操作符的优先级,以便我们可以按正确的顺序分解它。 The operators we have, in order of highest to lowest precedence, are:我们拥有的运算符按优先级从高到低是:

  • ( ... ) to give a section higher precedence ( ... )给予部分更高的优先级
  • postfix --后缀--
  • prefix --前缀--
  • +
  • > and < (left to right) >< (从左到右)
  • == (multiple times, left to right) == (多次,从左到右)

So we can calculate the sum in this order:所以我们可以按这个顺序计算总和:

  • the part inside the brackets is the only interesting part, the rest is 21 + (something) + 21括号内的部分是唯一有趣的部分,其余部分是21 + (something) + 21
  • a-- gives 1 , but changes a to 0 ( b+(a==1>a+a<--a==a)+b ) a--给出1 ,但将a更改为 0 ( b+(a==1>a+a<--a==a)+b )
  • --a changes a to -1 and gives -1 ( b+(a==1>a+a<-1==a)+b ) --aa更改为-1并给出-1 ( b+(a==1>a+a<-1==a)+b )
  • a is now -1 , so the very middle becomes -1+-1 ( b+(a==1>-1+-1<-1==a)+b ) which is -2 ( b+(a==1>-2<-1==a)+b ) a现在是-1 ,所以中间变成-1+-1 ( b+(a==1>-1+-1<-1==a)+b ) 即-2 ( b+(a==1>-2<-1==a)+b )
  • 1>-2 is true ( b+(a==true<-1==a)+b ) 1>-2trueb+(a==true<-1==a)+b
  • true<-1 is false because true is treated as 1 ( b+(a==false==a)+b ) true<-1false因为true被视为1 ( b+(a==false==a)+b )
  • a is -1 , but false is 0 , so a==false is like saying -1==0 , which is false ( b+(false==a)+b ) a-1 ,但false0 ,所以a==false就像说-1==0 ,这是falseb+(false==a)+b
  • false==a is again false ( b+(false)+b ) false==afalse ( b+(false)+b )
  • treated as a number, false is 0, so b + 0 + b is 21 + 0 + 21 is 42视为数字, false为 0,因此b + 0 + b21 + 0 + 2142

Interestingly, the in-place modification of a makes this open to various interpretations.有趣的是, a的就地修改使这对各种解释开放。 For instance, it might be that all the unmodified a s are substituted as 1 (ie before the a++ ), giving some variations:例如,可能所有未修改的a都被替换为1 (即在a++之前),给出了一些变化:

  • with a as 1 , the very middle is 1+1 ( b+(a==1>1+1<-1==a)+b ) which is 0 ( b+(a==1>2<-1==a)+b )a作为1 ,中间是1+1 ( b+(a==1>1+1<-1==a)+b ) 即0 ( b+(a==1>2<-1==a)+b )
  • 1>2 is false ( b+(a==false<-1==a)+b ) 1>2falseb+(a==false<-1==a)+b
  • however, false<-1 is still false , so we get back to our original sequence然而, false<-1仍然是false ,所以我们回到我们原来的序列

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM