Last active
January 28, 2023 00:00
-
-
Save conartist6/7fb060cfa7625e722d6795251d5673f0 to your computer and use it in GitHub Desktop.
ReadOnlyMap
This file contains hidden or 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
const _ = Symbol('private'); | |
class ReadOnlyMap { | |
constructor(map) { | |
this[_] = map; | |
} | |
static from(entries) { | |
return new ReadOnlyMap(new Map(entries)); | |
} | |
get size() { | |
return this[_].size; | |
} | |
has(type) { | |
return this[_].has(type); | |
} | |
get(type) { | |
return this[_].get(type); | |
} | |
set() { | |
throw new Error('readOnlyMap.set is unimplemented'); | |
} | |
delete() { | |
throw new Error('readOnlyMap.delete is unimplemented'); | |
} | |
clear() { | |
throw new Error('readOnlyMap.clear is unimplemented'); | |
} | |
keys() { | |
return this[_].keys(); | |
} | |
values() { | |
return this[_].values(); | |
} | |
entries() { | |
return this[_].entries(); | |
} | |
forEach(fn) { | |
return this[_].forEach(fn); | |
} | |
[Symbol.iterator]() { | |
return this[_][Symbol.iterator](); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment