Skip to content

Instantly share code, notes, and snippets.

View audinue's full-sized avatar

Audi Nugraha audinue

  • Surabaya, Jawa Timur, Indonesia
View GitHub Profile
@audinue
audinue / object-map.js
Last active October 30, 2020 02:35
Iterable safe plain JavaScript object as map.
function objectMap () {
return Object.defineProperty(Object.create(null), Symbol.iterator, {
configurable: true, // This descriptor is inspired by Map.prototype[Symbol.iterator]
writable: true,
value: function* () {
for (const key in this) {
yield [key, this[key]]
}
}
})