jQuery コードリーディング その2

まず、全体を俯瞰してみる。

  • ファイルサイズ:247KB
  • 総行数:9190行
  • 総文字数:247351文字

だいたい新聞朝刊二日分をくまなく読むくらいの量ですね。

では、読み始めます。
コメントは飛ばして15行目から。

(function( global, factory ) {

	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 inherently posses a window with a document
		// (such as Node.js), expose a jQuery-making 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 ) {

// Can't do this because several apps including ASP.NET trace
// the stack via arguments.caller.callee and Firefox dies if
// you try to trace through "use strict" call chains. (#13335)
// Support: Firefox 18+
//

いきなりわからん。というか最初だからこそわからないのか。
そもそも

}(typeof window !== "undefined" ? window : this, function( window, noGlobal ) {

の'{'に対応するカッコが見つからないんだが(viの % コマンドで探したが)...。
このコメントの意味がよく分からないけど、use strict をつけるとASP.NET, Firefoxでdieするのと関係あるの?よくわからん。もう少し、見てから戻ってきます。

// Can't do this because several apps including ASP.NET trace
// the stack via arguments.caller.callee and Firefox dies if
// you try to trace through "use strict" call chains. (#13335)
// Support: Firefox 18+
//

どんどんいこう。

var arr = [];

var slice = arr.slice;

var concat = arr.concat;

var push = arr.push;

var indexOf = arr.indexOf;

var class2type = {};

var toString = class2type.toString;

var hasOwn = class2type.hasOwnProperty;

var support = {};

arr で配列を準備。slice,concat,push,indexOfはarrのメソッドの対するエイリアス
class2type でプロパティを準備。プロパティは連想記憶(ハッシュ)と同じようなものだと理解している。toString, hasOwnはclass2typeのメソッドに対するエイリアス
support でプロパティを準備。

次回に続く。このペースでいくと何時終わるのやら。