Created
July 6, 2014 04:06
-
-
Save Gaubee/2f12ebbd529054c4a934 to your computer and use it in GitHub Desktop.
实例化函数多参数的实现方式
This file contains hidden or 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
var _no_new = {}; | |
var Cons = function (arg) { | |
if (!(this instanceof Cons)) { | |
var instance = new Cons(_no_new); | |
instance._init.apply(instance,arguments); | |
return instance; | |
} | |
if (arg !== _no_new) { | |
this._init.apply(this,arguments); | |
} | |
} | |
Cons.prototype._init = function(a,b,c) { | |
a&&(this.a = a); | |
b&&(this.b = b); | |
c&&(this.c = c); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment