问答详情
源自:1-4 jQuery整体架构

第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 );


提问者:qq_陈祥芬_0 2017-10-10 21:06

个回答

  • weixin_慕勒1565498
    2020-03-16 10:30:53

    (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,就是客户端,(浏览器)


  • Hope_pdm
    2017-10-30 19:39:26

    里面说过:(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未定义