Skip to content

Instantly share code, notes, and snippets.

@pwm
Last active August 16, 2016 15:27
Show Gist options
  • Save pwm/b21552de0505c0a4230eab53920ec967 to your computer and use it in GitHub Desktop.
Save pwm/b21552de0505c0a4230eab53920ec967 to your computer and use it in GitHub Desktop.
Useless stuff to help me remember some ES6 concepts
'use strict';
const Foo = (() => {
const params = new WeakMap();
class Foo {
constructor(bar, baz) {
params.set(this, {
'barKey': bar,
'bazKey': baz
});
}
[Symbol.iterator]() {
return (function* (o) {
for (let k of Object.keys(o)) {
yield [k, o[k]];
}
})(params.get(this));
}
}
return Foo;
})();
const foo1 = new Foo({1: 'bar1'}, {2: 'baz2'});
const foo2 = new Foo({3: 'bar3'}, {4: 'baz4'});
for (let [k, v] of [...foo1, ...foo2]) {
console.log(k, v);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment