104 points · by morphics · 12y ago · 32 comments
I remember playing with this for hours. Also, having to fix my box when it hit. :)
First, we set var '$' to bitwise NOT of [], which is -1 ([] casts to 0 or false depending on the operator):
$ = ~[];
Then we re-set $ to an object: $ = {___: ++$,
$$$$: (![]+"")[$],
...
Which gives us: $.___ == 0 // ($ was still -1, now it's 0)
$.$$$$ == "f" // I think
The "f" is a bit clever: ![] == false
(![]+"") == "false"
(![]+"")[$] is an index on the string, and $ is now 0
That's as far as I've bothered. (edited for formatting) window["alert"]("hello")Partially deobfuscated: http://jsbin.com/qiwib/1/edit?js,output
So he's doing 0["constructor"] which gives the constructor of a number, Number. Then he's 0["constructor"]["constructor"] gives the constructor of Number, which is like a function, so he gets Function.
var y = (0)["constructor"]["constructor"];
y == Function; // true
Then he basically does this ($.$ == Function): Function(
Function(
"return \"alert('I love you');\""
)()
)();
The inner function just returns the string "alert('I love you');", which then becomes the body for the outer function.I don't know why they didn't make it:
Function ("alert('I love you');")();
Maybe they needed more chars for the heart. That was a good little crash course in javascript Function constructors!
I thought it was just cleverly shaped code that did nothing, decidedly less impressive.
http://jsbin.com/yecuh/1/edit?js,console
(click run)