javascript - 我不知道这段代码是什么

标签 javascript jquery function syntax

我一直在到处寻找,但我不知道这段代码叫什么。我从 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 ) {...})

谁能帮帮我吗?

最佳答案

可以称为包装/自调用函数。但实际上它与函数没有什么不同。只是一个在定义时调用的简单函数 - 没有名称。因此,为什么在声明的末尾有一个直接传递的参数列表。

关于javascript - 我不知道这段代码是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39310635/

相关文章:

javascript - 使用 .match() 验证字符串

php - 下拉列表未使用 Yii 更新

javascript - 为什么jQuery只在部分链接进入函数?

function - 在 Clojure 中传递方法名称以进行评估的惯用方法?

javascript - 如何将动画滚动到特定ID减去X距离?

javascript - 为什么我的函数返回未定义? JS

javascript - 我怎样才能让这个 jQuery 脚本在 WordPress 上运行?

java - html 页面上的验证码图像链接

javascript - 如何从 Observable 中检索数据并在拦截器中使用它?

jquery - TinyMCE没有定义Jquery