[英]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 我从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. 只是调用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.