Skip to content

Instantly share code, notes, and snippets.

@MadLittleMods
Last active September 1, 2015 11:55
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 MadLittleMods/8dd8443de3923f4a1d0c to your computer and use it in GitHub Desktop.
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.
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