Created
August 18, 2012 14:48
-
-
Save cmarkle27/3387198 to your computer and use it in GitHub Desktop.
Resig Class Prototype
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
// makeClass - By John Resig (MIT Licensed) | |
function makeClass(){ | |
return function(args){ | |
if ( this instanceof arguments.callee ) { | |
if ( typeof this.init == "function" ) | |
this.init.apply( this, args.callee ? args : arguments ); | |
} else | |
return new arguments.callee( arguments ); | |
}; | |
} | |
var User = makeClass(); | |
User.prototype.init = function(first, last){ | |
this.name = first + " " + last; | |
}; | |
var user = User("John", "Resig"); | |
user.name | |
// => "John Resig" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment