jQuery 中,jQuery的构造方法是jQuery.fn.init(selector,context)
,是作为方法的返回值返回的。
var jQuery = function(selector,context){
return new jQuery.fn.init(selector,context);
}
当我们想用new jQuery来生成jquery对象也可以. 跟直接用jQuery()没区别.
因为构造函数一定会返回一个对象.如果显示指定了返回某个对象.就会返回那个对象, 否则才会返回this对象.
function Amm(){
this.name = 'amm';
this.say = function(){
console.log(this.name)
}
return new Bob();
}
function Bob(){
this.name = 'bob';
this.say = function(){
console.log(this.name)
}
}
var aa = new Amm()
aa.say() // 返回 'bob'
资料:
jquery队列机制
网友评论