You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was just glancing through some of your new ES6 based code — cool stuff! I just learned about this idea of using a WeakMap for private data today, partly from your example. I will make one observation in the usage of this in your 01-Stack3.js file however. In push() and pop() you have a pattern where you re-set the array on the itemsWeakMap after manipulating it, for instance:
let s = items.get(this);
s.push(element);
items.set(this, s);
Pretty sure it is unnecessary to set the array s after having gotten the reference to it. You didn't delete it, so you're just sharing that pointer s with the itemsWeakMap. That is, it's a pointer (really), not a copy of the array. So you should be able to omit the statement items.set(this, s);.
Cheers!
The text was updated successfully, but these errors were encountered:
Hi Loiane:
I was just glancing through some of your new ES6 based code — cool stuff! I just learned about this idea of using a
WeakMap
for private data today, partly from your example. I will make one observation in the usage of this in your 01-Stack3.js file however. Inpush()
andpop()
you have a pattern where you re-set the array on theitems
WeakMap
after manipulating it, for instance:Pretty sure it is unnecessary to set the array
s
after having gotten the reference to it. You didn'tdelete
it, so you're just sharing that pointers
with theitems
WeakMap
. That is, it's a pointer (really), not a copy of the array. So you should be able to omit the statementitems.set(this, s);
.Cheers!
The text was updated successfully, but these errors were encountered: