Last active
November 21, 2017 00:41
-
-
Save kevincennis/21a8d46af4cb7694b6ae26c870a44d97 to your computer and use it in GitHub Desktop.
Tiny jQuery Starter
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 $( selector, ctx = document ) { | |
if ( !( this instanceof $ ) ) { | |
return new $( selector, ctx ); | |
} | |
return this.push( ...ctx.querySelectorAll( selector ) ); | |
} | |
$.prototype = { | |
length: 0, | |
splice: Array.prototype.splice, | |
push: Array.prototype.push, | |
each( fn ) { | |
Array.prototype.forEach.call( this, ( e, i ) => { | |
fn.call( e, i, e ) | |
}); | |
return this; | |
}, | |
addClass( classname ) { | |
return this.each( ( i, e ) => { | |
e.classList.add( classname ); | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment