#jQuery.fn.init()
接收三个参数,selector,context,rootjQuery
默认的$()传的值实际上考虑了很多种情况,下面是返回值
-
false,undefined,null
return this;
-
node节点
this.context = this[0] = selector; this.length = 1; return this;
-
“body”
this.context = document; this[0] = document.body; this.selector = selector; this.length = 1; return this;
-
字符串,单独标签<tag></tag>
document.createElement; return jQuery.merge(this,selector)
-
字符串,复杂的HTML代码<span class=“a” >
jQuery.buildFragment; return jQuery.merge(this,selector)
-
字符串,#id
document.getElementById; this.context = document; this.selector = selector; return this;
-
字符串,选择器
return jQuery.find(selector);
-
字符串,选择器,context传值为$(…)
return context.find(selector);
-
字符串,选择器,context传值为非jquery对象
return this.constructor(context).find(selector);
7、8、9可以写成 return (context || rootjQuery).find(selector);
-
函数
return rootjQuery.ready(selector);
-
jquery对象//深拷贝
this.selector = selector.selector; this.context = selector.context;
-
其它
return jQuery.makeArray(selector,this);