jQuery源码分析

首先 jquery使用了匿名自调用的方式让函数加载;

1 (function( global, factory ) { 
2 if ( typeof noGlobal === strundefined ) {
3     window.jQuery = window.$ = jQuery;
4 }
5 return jQuery;
6 }));
if ( typeof module === "object" && typeof module.exports === "object" ) {
     //目前,对于合适的'windows'环境CommonJs 和 CommonJs-like执行这个方法获取到jquery,
    //对于没有'document'的'windows'环境(例如nodeJs)需要expose一个像 module.exports 的工厂,
    //例如: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 ); }
原文地址:https://www.cnblogs.com/liuyanan/p/4930003.html