Skip to content

Instantly share code, notes, and snippets.

@webshooter
Last active October 9, 2018 03:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webshooter/6d4cc20bb8cf05733302 to your computer and use it in GitHub Desktop.
Save webshooter/6d4cc20bb8cf05733302 to your computer and use it in GitHub Desktop.
Javascript class definition template
var Thing = (function() {
this.public_property = "Public property";
var private_property = "Private property";
function Thing(data) {
this.datum1 = data.datum1;
this.datum3 = data.datum2;
}
Thing.prototype.public_method1 = function() {
return "Public method 1 - " + this.datum1;
};
Thing.prototype.public_method2 = function() {
return "Public method 2 - " + private_method1();
};
function private_method1() {
return "Private method 1";
}
function private_method2() {
return "Private method 2";
}
function private_method3() {
return "Private method 3 - " + this.datum2;
}
return Thing;
})();
/* Example usage */
var thing = new Thing( { "datum1":"my data 1", "datum2":"my data 2" } );
console.log(thing.public_method1());
console.log(thing.public_method2());
console.log(public_property);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment