Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// class
var Greeter = (function () {
// constructor
function Greeter(message) {
// public variable
this.greeting = message;
}
// public function
Greeter.prototype.greet = function () {
return _getHello.call(this);
};
// private static variable
var _hello = "Hello";
// private function
function _getHello() {
return _hello + ", " + this.greeting + "!";
}
return Greeter;
})();
var greeter = new Greeter("world");
var msg = greeter.greet(); // = "Hello, world!"
alert(msg);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment