Created
July 3, 2015 01:41
-
-
Save josephjaniga/b0dd2df2bdfe3807236b to your computer and use it in GitHub Desktop.
Different type of javascript class definitions ES5
This file contains 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
// 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