Skip to content

Instantly share code, notes, and snippets.

@josephjaniga
Created July 3, 2015 01:41
Show Gist options
  • Save josephjaniga/b0dd2df2bdfe3807236b to your computer and use it in GitHub Desktop.
Save josephjaniga/b0dd2df2bdfe3807236b to your computer and use it in GitHub Desktop.
Different type of javascript class definitions ES5
// User Class
function User(){
this.first = "Joseph"; // public property
var middleName = "Anthony"; // private property
this.last = function(){ // public method
return "Janiga";
};
function getFullName(){ // private method
return this.first + " " + middle + " " + this.last();
};
this.printName = function(){
console.log(getFullName());
};
}
var joe = new User();
joe.first; // "Joseph"
// middleName - not exposed from this scope
joe.last(); // "Janiga"
// getFullName() - not exposed outside of the class body
joe.printName(); // "Joseph Anthony Janiga" - THIS however works because the printName method has access to the class scope
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment