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