Map.prototype.clear method

Jason Orendorff jason.orendorff at
Mon Oct 22 09:39:45 PDT 2012

An actual real-world user of ES6 Map (in Firefox-only code) is asking
for a .clear() method:

<jcranmer> I'm writing a mork reader in JS for mconley's new
addressbook (using JS workers, OS.File, and JS Maps !)
<jcranmer> one of the operations I need to be able to do amounts to
"clear the entire table"
<jcranmer> I can't just make it a new map, since I put other
properties on the map that I don't want to lose
<jcranmer> I'm doing this for now:
<jcranmer>       for (let [tid, value] of this._currentTable)
<jcranmer>         this._currentTable.delete(tid);
<jorendorff> why store those extra properties on this._currentTable
rather than directly on this?
<jcranmer> because I have multiple tables

In our current implementation, a builtin Map.prototype.clear method
that simply removes all entries from the Map would be quite a bit
faster than what jcranmer is currently doing.


More information about the es-discuss mailing list