Created
January 12, 2010 13:15
-
-
Save micmath/275174 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function Hello(name) { | |
// create context | |
var my = {}; | |
my.name = name || 'you'; | |
// define methods | |
function greet(name) { | |
name = name || my.name; | |
alert('Hello '+name+'.'); | |
} | |
// create instance | |
var instance = function(name) { | |
greet(name); | |
} | |
// populate instance | |
instance.greet = greet; | |
return instance; | |
} | |
var h1 = new Hello('World'); | |
var h2 = new Hello('Larry'); | |
//alert(h1 instanceof Function); // true | |
h1(); | |
h2(); | |
h2('everybody'); | |
h1.greet('Dolly'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment