Created
June 11, 2018 16:03
-
-
Save wonminjeon/1c55c84000e3257b8659d55b2b99fabe to your computer and use it in GitHub Desktop.
Because you want the $ of jQuery without the jQuery.
This file contains hidden or 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
| // based on https://gist.github.com/paulirish/12fb951a8b893a454b32 | |
| const $ = document.querySelector.bind(document); | |
| const $$ = document.querySelectorAll.bind(document); | |
| Node.prototype.on = window.on = function (name, fn) { | |
| this.addEventListener(name, fn); | |
| }; | |
| NodeList.prototype.__proto__ = Array.prototype; // eslint-disable-line | |
| NodeList.prototype.on = NodeList.prototype.addEventListener = function (name, fn) { | |
| this.forEach((elem) => { | |
| elem.on(name, fn); | |
| }); | |
| }; | |
| export { $, $$ }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment