Last active
October 9, 2018 03:58
-
-
Save webshooter/6d4cc20bb8cf05733302 to your computer and use it in GitHub Desktop.
Javascript class definition template
This file contains hidden or 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
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