Skip to content

Instantly share code, notes, and snippets.

@csainty
Created March 10, 2012 01:54
Show Gist options
  • Save csainty/2009690 to your computer and use it in GitHub Desktop.
Save csainty/2009690 to your computer and use it in GitHub Desktop.
var Person = (function() {
var ctor = function(name) {
var _name = name;
this.get_name = function() { return _name; } // Wrap the private variable with a getter
};
ctor.prototype.sayHello = function () {
console.log("Hello " + this.get_name());
}
return ctor;
})();
var sue = new Person('sue');
var bill = new Person('bill');
sue.sayHello(); // prints Hello sue
bill.sayHello(); // prints Hello bill
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment