##jquery源码分析
选择网页元素
###js基础知识
匿名函数声明完就立即执行
!function(a,b)(pa, pb);
等同于(function(a,b))(pa, pb);
prototype
###使用方法 jQuery(“ul>li:first”).addClass(“selected”);
其中jQuery()可替换为快捷方式$(),如果$被其它对象占用,可使用jQuery.noConflict()函数取消快捷方式。
###$().xxx()
$()返回一个对象
分析一:jQuery的无new构建
JavaScript是函数式语言,函数可以实现类,类就是面向对象编程中最基本的概念
复制代码
var aQuery = function(selector, context) {
//构造函数
}
aQuery.prototype = {
//原型
name:function(){},
age:function(){}
}
var a = new aQuery();
a.name();
var aQuery = function(selector, context) {
return aQuery.prototype.init();
}
aQuery.prototype = {
init:function(){
return this;
}
name:function(){},
age:function(){}
}
A = n.fn.init = function(a, b) {
var c, d;
if (!a) return this;
if ("string" == typeof a) {
if (c = "<" === a[0] && ">" === a[a.length - 1] && a.length >= 3 ? [null, a, null] : z.exec(a), !c || !c[1] && b) return ! b || b.jquery ? (b || y).find(a) : this.constructor(b).find(a);
if (c[1]) {
if (b = b instanceof n ? b[0] : b, n.merge(this, n.parseHTML(c[1], b && b.nodeType ? b.ownerDocument || b: l, !0)), v.test(c[1]) && n.isPlainObject(b)) for (c in b) n.isFunction(this[c]) ? this[c](b[c]) : this.attr(c, b[c]);
return this
}
return d = l.getElementById(c[2]),
d && d.parentNode && (this.length = 1, this[0] = d),
this.context = l,
this.selector = a,
this
}
return a.nodeType ? (this.context = this[0] = a, this.length = 1, this) : n.isFunction(a) ? "undefined" != typeof y.ready ? y.ready(a) : a(n) : (void 0 !== a.selector && (this.selector = a.selector, this.context = a.context), n.makeArray(a, this))
};
A.prototype = n.fn,