Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.