Skip to content

Instantly share code, notes, and snippets.

@conartist6
Last active January 28, 2023 00:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conartist6/7fb060cfa7625e722d6795251d5673f0 to your computer and use it in GitHub Desktop.
Save conartist6/7fb060cfa7625e722d6795251d5673f0 to your computer and use it in GitHub Desktop.
ReadOnlyMap
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