下面的代码也能实现相同的功能,为何要引入 fn.init 这个东西呢? 好处是什么?
var $$$ = ajQuery2 = function(selector) {
if(!(this instanceof(ajQuery2))){
return new ajQuery2(selector);
}
this.selector = selector;
}
ajQuery2.prototype = {
name: 'aaron',
init: function(selector) {
this.selector = selector;
return this;
},
constructor: ajQuery2
}
var a = ajQuery2("abc");
console.dir(a);