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.
- What? People create getters and setters to private variables all the time. It in no way violates the reason for the variable being private. It's called encapsulation.castletheperson– castletheperson2016-05-16 03:47:20 +00:00Commented May 16, 2016 at 3:47
- @4castle - Yes, but from outside the object you can't access the variable itself, all you can do is call the getter and setter. (And in this case the OP said they can't change the constructor function, so they can't add a getter or setter.)nnnnnn– nnnnnn2016-05-16 03:48:37 +00:00Commented May 16, 2016 at 3:48
- @nnnnnn I'm just objecting to their description of a private variable. In many cases, it isn't done simply to restrict access to the variable, it's done for encapsulation. It's the difference between "reason" and "definition".castletheperson– castletheperson2016-05-16 03:52:10 +00:00Commented May 16, 2016 at 3:52
- @4castle the OP wants to ab able to access the variable without making any changes to the code he provided. So given this code if at all the private variable is made accessible then it violates the purpose of private variable. But yes with code changes it can be done..Rajshekar Reddy– Rajshekar Reddy2016-05-16 03:52:20 +00:00Commented May 16, 2016 at 3:52
Add a comment |
How to Edit
- Correct minor typos or mistakes
- Clarify meaning without changing it
- Add related resources or links
- Always respect the author’s intent
- Don’t use edits to reply to the author
How to Format
- create code fences with backticks ` or tildes ~ ```
like so
``` - add language identifier to highlight code ```python
def function(foo):
print(foo)
``` - put returns between paragraphs
- for linebreak add 2 spaces at end
- _italic_ or **bold**
- indent code by 4 spaces
- backtick escapes
`like _so_` - quote by placing > at start of line
- to make links (use https whenever possible) <https://example.com>[example](https://example.com)<a href="https://example.com">example</a>
How to Tag
A tag is a keyword or label that categorizes your question with other, similar questions. Choose one or more (up to 5) tags that will help answerers to find and interpret your question.
- complete the sentence: my question is about...
- use tags that describe things or concepts that are essential, not incidental to your question
- favor using existing popular tags
- read the descriptions that appear below the tag
If your question is primarily about a topic for which you can't find a tag:
- combine multiple words into single-words with hyphens (e.g. python-3.x), up to a maximum of 35 characters
- creating new tags is a privilege; if you can't yet create a tag you need, then post this question without it, then ask the community to create it for you
lang-js