【发布时间】:2016-09-03 19:32:24
【问题描述】:
我一直在到处寻找和寻找,但我不知道这段代码叫什么。我是从 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 ) {...})
谁能帮帮我?
【问题讨论】:
-
这是一个包装器,用于支持加载脚本的不同方式。它允许它与必须使用
exports和require()的 CommonJS 样式的模块系统(例如在 NodeJS 中)一起使用,以及通过定义一个全局变量在浏览器中使用。 UMDjs 项目提供了各种组合的模板。 -
请让 cmets 保持文明和建设性。
-
嗯。如果这是我,我也想知道,但每条评论都被删除了
-
好吧,我是专业人士github.com/XtremePlayzCODE
-
在澄清问题方面并不是完全有用的 cmets...无论如何 - 继续前进...
标签: javascript jquery function syntax