Skip to content

Instantly share code, notes, and snippets.

@roman01la
Created February 18, 2015 00:41
Show Gist options
  • Save roman01la/a382359845f9067e9387 to your computer and use it in GitHub Desktop.
Save roman01la/a382359845f9067e9387 to your computer and use it in GitHub Desktop.
Property with a custom getter to get merged Set objects as a single Set
let obj = {
a: new Set([1,2,3]),
b: new Set([4,2,6,7]),
c: new Set([6,2,1,0])
};
Object.defineProperties(obj, {
all: {
get() { return new Set([...Object.keys(this).reduce((a, b) => [...(this[a] || a), ...this[b]])]); }
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment