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*

7
  • 18
    "scoping in reverse" is a C++ feature with the "friend" keyword. Esentially any function should define it's prototype as it's friend. Sadly this concept is C++ and not JS :( Commented Sep 21, 2013 at 18:22
  • 1
    I would like to add this post to the top of my favorites list and keep it there. Commented Apr 16, 2016 at 21:11
  • 2
    I don't see the point of this- you're only adding a layer of abstraction that doesn't do anything. You may as well just make secret a property of this. JavaScript simply doesn't support private variables with prototypes as prototypes are bound to the call-site context, not the 'creation-site' context. Commented Jan 7, 2017 at 13:03
  • 1
    Why not just do person.getSecret() then? Commented Feb 28, 2017 at 10:53
  • 1
    Why does this have so many upvotes? This doesn't make the variable private. As mentioned above using person.getSecret() will let you access that private variable from anywhere. Commented Jul 18, 2018 at 19:17