Skip to content

Instantly share code, notes, and snippets.

@danielhusar
Last active August 29, 2015 14:10
Show Gist options
  • Save danielhusar/6030dcf3e615e7f482f1 to your computer and use it in GitHub Desktop.
Save danielhusar/6030dcf3e615e7f482f1 to your computer and use it in GitHub Desktop.
Simpliest jQuery ever
(function(window, document, undefined) {
function jQuery(selector) {
this.el = this.slice.call(document.querySelectorAll(selector));
this.length = this.el.length;
this.el.forEach(function (element, index) {
this[index] = element;
}, this);
return this;
}
jQuery.prototype = {
each: function (fn) {
this.el.forEach(function (element, index) {
fn.apply(element, [element, index]);
});
return this;
},
slice : [].slice,
splice : [].splice
};
function $(selector) {
return new jQuery(selector);
}
window.$ = $;
}(this, this.document));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment