Skip to content

Instantly share code, notes, and snippets.

@copenhas
Created February 3, 2011 03:26
Show Gist options
  • Select an option

  • Save copenhas/808999 to your computer and use it in GitHub Desktop.

Select an option

Save copenhas/808999 to your computer and use it in GitHub Desktop.
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