在console中执行如下:
var aQuery = function(selector) {
if (!(this instanceof aQuery)) {
console.log(this); //window
console.log('zeze');//zeze
return new aQuery(selector);//疑问:这块不是直接return了吗?为何下面的ddd会输出。
}
console.log('ddd');//ddd
var elem = document.getElementById(/[^#].*/.exec(selector)[0]);
this.length = 1;
this[0] = elem;
this.context = document;
this.selector = selector;
this.get = function(num) {
return this[num];
}
console.log(this); //aQuery
return this;
}
aQuery('#hehe').length; //1