My experience with various programming languages leads me to believe that the answer is likely a resounding no, except for PHP which had some peculiar cases like $someArray['nonexistentKey']++
.
I'm interested in creating a sparse object where each property functions as a numeric counter. If a counter is not defined, it should default to 0 and automatically initialize itself to 0 if you attempt to increment it.
In essence, I want to customize the Object getter to return 0
instead of
undefined</code... or possibly define the property right there during the <code>get
operation and set it to 0
.
This means that any undefined property would get initialized to zero upon get
. For example:
myObj['hugePrimeNumberToBaseXToString']++;
would then result in the property being set to 1.
In the past, using something like Object.__proto__
may have been a solution for this scenario...