Skip to content

Instantly share code, notes, and snippets.

@slikts
Created May 6, 2016 20:52
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 slikts/562e07b4bf57c1f6af98c8054f0a75ef to your computer and use it in GitHub Desktop.
Save slikts/562e07b4bf57c1f6af98c8054f0a75ef to your computer and use it in GitHub Desktop.
'use strict'
class Attrs extends Array {
constructor(els, name) {
super()
Object.assign(this, {els, name})
}
get() {
return Object.assign(this, this.els.map(el => el.getAttribute(name)))
}
set(value) {
return this.els.each(el => el.setAttribute(this.name, value))
}
remove() {
return this.els.each(el => el.removeAttribute(this.name))
}
}
class Selecty extends Array {
attr(name, value = null) {
let attrs = new Attrs(this, name)
if (value != null) {
return attrs.set(value)
}
return attrs.get()
}
each(fn) {
this.every((...args) => fn(...args) !== false)
return this
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment