Created
July 27, 2011 03:56
-
-
Save nulltask/1108640 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
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