|
|
|
|
|
by adam-a
4517 days ago
|
|
It's quite clever, the script gets a reference to the function prototype by making the string "constructor" and calling (0)["constructor"]["constructor"]. Calling Function on a string returns a new function with the string as the body, which you can then execute. 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.
Then he basically does this ($.$ == Function): 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!