Skip to content

Instantly share code, notes, and snippets.

@dawnerd
Created March 30, 2016 16:55
Show Gist options
  • Save dawnerd/1e4eb8c3c2df24678608528dee606cb8 to your computer and use it in GitHub Desktop.
Save dawnerd/1e4eb8c3c2df24678608528dee606cb8 to your computer and use it in GitHub Desktop.
class Domodule {
constructor(el) {
this.el = el;
this.els = {};
for (const action of this.find('[data-action]')) {
action.addEventListener(
action.dataset.actionType || 'click',
this[action.dataset.action].bind(this)
);
}
for (const named of this.find('[data-name]')) {
this.els[named.dataset.name] = named;
}
// NOTE: Do we want to return the class instance or the el?
return this;
}
find(selector) {
return this.el.querySelectorAll(selector);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment