Map.prototype.clear method

Brendan Eich brendan at mozilla.org
Mon Oct 22 10:40:14 PDT 2012


+1, no brainer. Thanks for supplying the brain!

/be

Jason Orendorff wrote:
> 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.
>
> -j
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>


More information about the es-discuss mailing list