Created
February 3, 2011 03:26
-
-
Save copenhas/808999 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Person() { | |
| //public member | |
| this.Name = "Copenhaver"; | |
| //convention based "private" | |
| this._ccn = "5555555555555"; | |
| /* thought this was unusable, but it's actually scoped inside | |
| * this invocation of the function and usable by other members of | |
| * the object currently being built. | |
| var ssn = "xxxxxxxxx"; | |
| } | |
| /* this is actually creating a completely separate object that | |
| * will act as the parent of all objects built using Person() | |
| Person.prototype = { | |
| getSSN: function(){ | |
| //this doesn't do what you want | |
| //actually would try to grab this out of global scope | |
| return ssn; | |
| }, | |
| getCCN: function(){ | |
| //anyone could access this variable | |
| return this._ccn; | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment