jQuery是一个出色的javascript框架,所有的声明 实现位于一个文件里面,语法非常晦涩难懂,譬如下面

(function(){

var

// Will speed up references to window, and allows munging its name.

window = this,

// Will speed up references to undefined, and allows munging its name.

undefined,

// Map over jQuery in case of overwrite

_jQuery = window.jQuery,

// Map over the $ in case of overwrite

_$ = window.$,

jQuery = window.jQuery = window.$ = function( selector, context ) {

// The jQuery object is actually just the init constructor ‘enhanced’

return new jQuery.fn.init( selector, context );

},

// A simple way to check for HTML strings or ID strings

// (both of which we optimize for)

quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#([\w-]+)$/,

// Is it a simple selector

isSimple = /^.[^:#\[\.,]*$/;

jQuery.fn = jQuery.prototype = {

init: function( selector, context ) {

首先(function(){…})应该是一个匿名的javascript类,将所有的变量,函数声明封装起来,不至于暴露到全局的naming space中去, 然后声明了一些变量 并赋给window,再重新暴露出去,以便外部接口使用,譬如window.$,这是function(selector, context )的缩写,这些语法普通的javascript教程似乎都不怎么提及,这让我想起另外一个暴露接口的方法,也让人迷惑不解,

window['MGJS_CMT'] = {};
window['MGJS_CMT']['reply'] = reply;
window['MGJS_CMT']['quote'] = quote;