Last active
August 16, 2016 15:27
-
-
Save pwm/b21552de0505c0a4230eab53920ec967 to your computer and use it in GitHub Desktop.
Useless stuff to help me remember some ES6 concepts
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'; | |
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