Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

2
  • If you don't explicitly destroy an instance of Person before it goes out of scope doesn't the weakmap keep a reference to it so you'll have a memory leak? I came up with a pattern for protected as other instances of Person can access the variable and those inheriting from Person can. Just fiddled it out so not sure if there are any dis advantages other than extra processing (doesn't look as much as accessing the privates) stackoverflow.com/a/21800194/1641941 Returning a private/protected object is a pain since calling code can then mutate your private/protected. Commented Feb 16, 2014 at 14:22
  • 2
    @HMR Yeah, you have to explicitly destroy the private data. I'm going to add this caveat to my answer. Commented Feb 16, 2014 at 23:27