Skip to content

Instantly share code, notes, and snippets.

@nulltask
Created July 27, 2011 03:56
Show Gist options
  • Save nulltask/1108640 to your computer and use it in GitHub Desktop.
Save nulltask/1108640 to your computer and use it in GitHub Desktop.
function Klass(name) {
if (!(this instanceof Klass)) {
return new Klass(name);
}
this.name = name;
}
Klass.prototype.greeting = function() {
alert('Hi, My name is ' + this.name + '!');
};
var bob = Klass('Bob');
var alice = new Klass('Alice');
console.log(bob.greeting()); // Hi, My name is Bob!
console.log(alice.greeting()); // Hi, My name is Alice!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment