Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kevincennis
Last active November 21, 2017 00:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevincennis/21a8d46af4cb7694b6ae26c870a44d97 to your computer and use it in GitHub Desktop.
Save kevincennis/21a8d46af4cb7694b6ae26c870a44d97 to your computer and use it in GitHub Desktop.
Tiny jQuery Starter
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