C. Morgan
C. Morgan

Reputation: 75

I have no idea what this code is

I have been looking and looking and looking everywhere and I have no idea what this piece of code is called. I pulled it from jQuery

( function( global, factory ) {

"use strict";

if ( typeof module === "object" && typeof module.exports === "object" ) {

    // For CommonJS and CommonJS-like environments where a proper `window`
    // is present, execute the factory and get jQuery.
    // For environments that do not have a `window` with a `document`
    // (such as Node.js), expose a factory as module.exports.
    // This accentuates the need for the creation of a real `window`.
    // e.g. var jQuery = require("jquery")(window);
    // See ticket #14549 for more info.
    module.exports = global.document ?
        factory( global, true ) :
        function( w ) {
            if ( !w.document ) {
                throw new Error( "jQuery requires a window with a document" );
            }
            return factory( w );
        };
} else {
    factory( global );
}

// Pass this if window is not defined yet
} )( typeof window !== "undefined" ? window : this, function( window, noGlobal ) {...})

Can anyone help me out?

Upvotes: 1

Views: 2078

Answers (2)

Kesem David
Kesem David

Reputation: 2235

If you're asking about the syntax of the code which might look weird to you, this is what called a 'self invoked function'.

Which is a function that is being invoked right away, not declaring its's name. just invoking it.

Upvotes: 0

Caspar Wylie
Caspar Wylie

Reputation: 2833

Could be known as a wrapped/ self invoked function. But really its no different to a function. Just a humble function that gets called on definition - without a name. Hence why, at the end of the declaration, there is a list of arguments being passed straight through.

Upvotes: 2

Related Questions