简体   繁体   中英

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM