Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaring functions inside anonymous function

I am looking at code that appears to be declaring a function that would need to be called to run. This function is being declared within an anonymous function. Doesn't this mean that the function will be inaccessible to anything outside of this block?

(function () {
    var _d = vjo.dsf.EventDispatcher;
    var _r = vjo.Registry;

    function $1(p0) {
        return function (event) {
            return this.onSubmit(p0, event);
        };
    };
})();

Why would someone do this? I am not sure of the purpose/relevance of $ in this code.

like image 487
Nate Avatar asked Dec 01 '12 01:12

Nate


1 Answers

"Doesn't this mean that the function will be inaccessible to anything outside of this block?"

Yes it does.

"Why would someone do this?"

Usually because it contains code for internal use only, though in your example, the function is never invoked.

"I am not of the purpose/relevance of "$" in this code."

No relevance. Just another valid variable character.

like image 156
I Hate Lazy Avatar answered Sep 19 '22 01:09

I Hate Lazy