Last active
September 1, 2015 11:55
-
-
Save MadLittleMods/8dd8443de3923f4a1d0c to your computer and use it in GitHub Desktop.
My version of bling.js, https://gist.github.com/paulirish/12fb951a8b893a454b32. ES6, a little bit encapsulated.
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
let $ = document.querySelectorAll.bind(document); | |
Node.prototype.on = window.on = function(names, fn) { | |
names.split(/\s/).forEach(function(name) { | |
this.addEventListener(name, fn); | |
}.bind(this)); | |
// Keep the chaining going | |
return this; | |
}; | |
HTMLCollection.prototype.__proto__ = Array.prototype; | |
NodeList.prototype.__proto__ = Array.prototype; | |
NodeList.prototype.on = NodeList.prototype.addEventListener = function(name, fn) { | |
this.forEach(function(elem) { | |
elem.on(name, fn); | |
}); | |
// Keep the chaining going | |
return this; | |
}; | |
export default $; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment