Created
May 6, 2016 20:52
-
-
Save slikts/562e07b4bf57c1f6af98c8054f0a75ef to your computer and use it in GitHub Desktop.
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
'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