Skip to content

Instantly share code, notes, and snippets.

@micmath
Created January 12, 2010 13:15
Show Gist options
  • Save micmath/275174 to your computer and use it in GitHub Desktop.
Save micmath/275174 to your computer and use it in GitHub Desktop.
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