This file contains 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
// 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