I'm creating javascript library like jQuery, I have successfully adding prototype html() but if I call it with $(selector) it return object like {'el' : [array]} and if change in function to return this.el; it return array but I can't call .html().
How it can return [array] instead without breaking prototype?
window.$ = function(selector) {
if (!(this instanceof $)) {
return new $(selector);
}
this.el = [];
this.html = function(str) {
this.el.forEach(function(el) {
el.innerHTML = str;
});
};
(function(self) {
for (var eList = document.querySelectorAll(selector), i = eList.length - 1; i > -1; i--) {
self.el[i] = eList[i];
}
})(this);
return this;
};
$('#test').html('BBBBB')
console.log($('#test')[0])
<div id="test">AAAAAAA</div>
