· 7 years ago · Dec 02, 2018, 05:14 PM
1// makeClass - By John Resig (MIT Licensed)
2function makeClass(){
3 return function(args){
4 if ( this instanceof arguments.callee ) {
5 if ( typeof this.init == "function" )
6 this.init.apply( this, args.callee ? args : arguments );
7 } else
8 return new arguments.callee( arguments );
9 };
10}
11
12var User = makeClass();
13User.prototype.init = function(first, last){
14 this.name = first + " " + last;
15};
16var user = User("John", "Resig");
17user.name
18// => "John Resig"