1

I'm debugging an app that uses .NET's scriptmanager.

It may be a glitch in firebug, but when I read through the code there are a lot of lines like the following:

// anonymous functions not attached as handlers and not called immediately
function () {
    //code
}

// named functions added as methods
myObj = {
    myMethod: function myFunctionName() {
        //code
    }

}

Are these lines valid and, if so, what do they do and what possible reason would there be for coding like this (and I won't accept "It's microsoft - what d'you expect" as an answer)?

wheresrhys
  • 22,558
  • 19
  • 94
  • 162

2 Answers2

2

This might be worth a read: How does an anonymous function in JavaScript work?

Community
  • 1
  • 1
firefox1986
  • 1,602
  • 11
  • 9
  • That offers a bit of justification for double-naming a method (though I don't think the methods in the scriptmanager code were referring to themselves, so it's still a mystery to me why the methods are double-named). As for the unexecuted and unattached anonymous functions... still at a loss as to why they're there – wheresrhys Mar 24 '11 at 12:42
1

They are there because some busy programmer was intending to do something and ran out of time, but left the stub as a reminder of work to be done. They do nothing as of yet.

or to watermark the code for checks that are done elsewhere in the logic

or simply put there to obfuscate...

NicMartel
  • 11
  • 1