Skip to content

Instantly share code, notes, and snippets.

@akhansari
Created September 29, 2014 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akhansari/171fde94d201c4f69847 to your computer and use it in GitHub Desktop.
Save akhansari/171fde94d201c4f69847 to your computer and use it in GitHub Desktop.
// 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