Skip to content

Instantly share code, notes, and snippets.

@cmarkle27
Created August 18, 2012 14:48
Show Gist options
  • Save cmarkle27/3387198 to your computer and use it in GitHub Desktop.
Save cmarkle27/3387198 to your computer and use it in GitHub Desktop.
Resig Class Prototype
// 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