Last active
August 29, 2015 14:10
-
-
Save danielhusar/6030dcf3e615e7f482f1 to your computer and use it in GitHub Desktop.
Simpliest jQuery ever
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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