Skip to content

Instantly share code, notes, and snippets.

@andregoncalves
Last active November 18, 2017 12:04
Show Gist options
  • Save andregoncalves/5068797365f99028bdb2b7e6d6011440 to your computer and use it in GitHub Desktop.
Save andregoncalves/5068797365f99028bdb2b7e6d6011440 to your computer and use it in GitHub Desktop.
jQuery like syntax with ES6 #es6
/**
* --------------------------------------------------------------------
* jQuery compatibility layer
* --------------------------------------------------------------------
*/
window.$ = document.querySelectorAll.bind(document);
Node.prototype.on = window.on = function (name, fn) {
this.addEventListener(name, fn);
};
NodeList.prototype.on = NodeList.prototype.addEventListener = function (name, fn) {
[].forEach.call(this, function (el, i) {
el.on(name, fn);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment