Skip to content

Instantly share code, notes, and snippets.

@Gaubee
Created July 6, 2014 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gaubee/2f12ebbd529054c4a934 to your computer and use it in GitHub Desktop.
Save Gaubee/2f12ebbd529054c4a934 to your computer and use it in GitHub Desktop.
实例化函数多参数的实现方式
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