Created
March 10, 2012 01:54
-
-
Save csainty/2009690 to your computer and use it in GitHub Desktop.
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
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