Reputation: 10148
I'm reviewing an outsourced project for a friend and there is a really odd Javascript code block right at the top of each page. Clearly it doesn't do anything but it's so trippy I can't help but wonder how the capital F' it came to be:
(function() {
with (this[2]) {
with (this[1]) {
with (this[0]) {
return function(event) {};
}
}
}
})
Unless I'm missing something a developer would have to be influenced by some kind of amphetamine in order to produce this on their own so I'm assuming it's the remains of an automated tool but can't for the life of me imagine a useful scenario.
Can anyone shed some light on this? Has anyone encountered anything similar?
This is absolutely positively everything with exception to the opening <script>
tag from byte zero in the document. As already stated I'm aware that it doesn't do anything - even if the expression was executed this
would be the window
or global
which wouldn't have any numeric indices so it fails dismally at the first line.
I'm aware that with
as a concept leaves much to be desired and as a practical joke it's not funny. I'll leave the question open - maybe some monkey in a closet somewhere knows something about it.
Upvotes: 11
Views: 373
Reputation: 362
According to [MDN][1] the with statement is used to include an object into the statements within.
I just stumbled across a similar piece of code in Chrome.
I made a mistake of using the "in" keyword as a var/object and it replaced my code it the nested "withs", it replaced the code only in the dev tools sources file.
So it is from a debugger, the with statements were probably used in its code to organize the hierarchy of the JS, it came across the "in" and found nothing to find something in.
I gave up on the file (I was testing SSE and... failed) so I am now trying to recreate the error.
Upvotes: 0
Reputation: 36005
This might be of interest... it seems it's coming from a debugger. Which debugger I know not, nor why it would add such odd code:
Why is this function being undone?
Perhaps you could ask Scott Severance?
All that being said, I'd personally prefer the term ape-like descendant...
Please Note: This question was definitely rather random, but I especially like the fact that the (at least partial) answer was found already existing on StackOverflow...?! Is there anything that SO doesn't have an answer for, it's getting like one of those people who never likes to admit they don't know something!
Upvotes: 2