Last active
November 18, 2017 12:04
-
-
Save andregoncalves/5068797365f99028bdb2b7e6d6011440 to your computer and use it in GitHub Desktop.
jQuery like syntax with ES6 #es6
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
/** | |
* -------------------------------------------------------------------- | |
* 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