Skip to content

Don't need to re-set items array #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wruth opened this issue Jan 29, 2016 · 1 comment
Closed

Don't need to re-set items array #11

wruth opened this issue Jan 29, 2016 · 1 comment

Comments

@wruth
Copy link
Contributor

wruth commented Jan 29, 2016

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. In push() and pop() you have a pattern where you re-set the array on the items WeakMap 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 items WeakMap. 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!

@loiane
Copy link
Owner

loiane commented Feb 6, 2016

Thanks for the PR!

@loiane loiane closed this as completed Feb 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants