Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obscure nested "with" statements

Tags:

javascript

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.

like image 629
Emissary Avatar asked Feb 07 '14 21:02

Emissary


1 Answers

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!

like image 103
Pebbl Avatar answered Nov 05 '22 07:11

Pebbl