第2行至第7是什么意思
(function(global, factory) {
factory(global);
}(typeof window !== "undefined" ? window : this, function(window, noGlobal) {
var jQuery = function( selector, context ) {
return new jQuery.fn.init( selector, context );
2017-10-10
(function(global, factory) { factory(global); }(typeof window !== "undefined" ? window : this, function(window, noGlobal) { var jQuery = function( selector, context ) { return new jQuery.fn.init( selector, context );等价于(function(global) { var factory=function(global, undenfined) { var jQuery = function( selector, context ) { return new jQuery.fn.init( selector, context ); } }})(typeof window !== "undefined" ? window : this); // 其实这一部分是用来判断jQ运行环境的,第一运行环境是node.js类似CommonJS和CommonJ,第二个环境是window,就是客户端,(浏览器)
里面说过:(function(global, factory) {
factory(global);
}(typeof window !== "undefined" ? window : this, function(window, noGlobal) {
var jQuery = function( selector, context ) {
return new jQuery.fn.init( selector, context );等价于
(function(global) {
var factory=function(global, undenfined) {
var jQuery = function( selector, context ) {
return new jQuery.fn.init( selector, context );
}
}
})(typeof window !== "undefined" ? window : this);
factory参数传入的是个function,就是后面括号里的function(window, noGlobal) window=global,noglobal可看作undenfined未定义
举报