var $ = (function(){
function jQuery() {
this.elms = null;
return this;
}
jQuery.prototype.query = function(query) {
this.elms = document.querySelectorAll(query);
return this;
}
jQuery.prototype.text = function(str){
if(!this.elms) return this;
Array.prototype.forEach.call(this.elms, function(elm){
elm.textContent = str;
});
console.log(this);
return this;
}
return function(query){
var $ = new jQuery;
return $.query(query);
};
})();
$('.a').text('X');
second
var $ = (function(){
var elms = null, self = {
text: function(str){
if(!elms) return this;
Array.prototype.forEach.call(elms, function(elm){
elm.textContent = str;
});
return this;
}
};
return function(query){
elms = document.querySelectorAll(query);
return self;
};
})();
тут chain можно сделать
$('.a').text('t').text('z')
nvm, thx