The JavaScript map has 2 get and has methods. The get method returns undefined if the element does not exist , or if the undefined value has been added to the map .
So, if I implement my GetAlways method or one that returns an existing one or adds a new one and returns, if not, then I am stuck with the choice of sacrificial performance at runtime, providing a dual search map or sacrificing an API cleanliness equating undefined to nonexistence on the map and thereby effectively prohibiting the safe addition of undefined values ββto the map.
Is there a third efficient and clean choice similar to TryGet from C # ?
Code for unclean choices:
Map.prototype.GetAlways = function(name){ let child = this.get(name); if (child === undefined){
Code for slow selection:
Map.prototype.GetAlways = function(name){ if(this.has(name))
source share