jQuery是一種著名的JavaScript庫,它能夠使JavaScript開發(fā)更加簡(jiǎn)單、方便和快速。而jQuery3.1.js則是它的最新版本,其中中文注釋更是對(duì)于開發(fā)者學(xué)習(xí)理解有著不可替代的作用。
/*! * jQuery JavaScript Library v3.1.0 * https://jquery.com/ * * Includes Sizzle.js * https://sizzlejs.com/ * * Copyright jQuery Foundation and other contributors * Released under the MIT license * https://jquery.org/license * * Date: 2016-07-07T21:35Z */ ( function( global, factory ) { "use strict"; if ( typeof module === "object" && typeof module.exports === "object" ) { // Support: Node.js // For environment other than browser, export jQuery factory function. // In a browser scenario, window.jQuery is assigned with the factory function. // Here, jQuery becomes module.exports itself (+ its properties). 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 ) { var deletedIds = []; var document = window.document; var slice = deletedIds.slice; var concat = deletedIds.concat; var push = deletedIds.push; var indexOf = deletedIds.indexOf; ...
以上代碼是jQuery3.1.js的開頭部分,它首先是一個(gè)自執(zhí)行函數(shù),然后通過判斷當(dāng)前是否處于Node.js環(huán)境下,來進(jìn)行不同的全局變量和模塊導(dǎo)出操作。此外,它聲明了一些常用的變量,例如刪除的id數(shù)組deletedIds,文檔document,以及slice、concat、push和indexOf數(shù)組方法的變量。這些變量在后續(xù)的代碼中會(huì)被大量使用。