ut1l
Version:
Utility stuff
49 lines (44 loc) • 1.08 kB
JavaScript
var addProto, createBuilder, defineProperty;
defineProperty = Object.defineProperty;
addProto = defineProperty !== void 0 ? function(func, proto) {
func.prototype = proto;
defineProperty(func, "prototype", {
enumerable: false
});
} : function(func, proto) {
func.prototype = proto;
};
createBuilder = function(extend, constructor, prototype) {
var F, f, key, value;
if (typeof extend === "function") {
prototype = constructor;
constructor = extend;
extend = null;
} else if ((constructor == null) && (prototype == null)) {
prototype = extend;
extend = null;
}
F = constructor != null ? function(args) {
var ret;
ret = constructor.apply(this, args);
if (ret !== void 0) {
return ret;
} else {
return this;
}
} : function() {};
if (prototype == null) {
prototype = {};
}
F.prototype = prototype;
f = function() {
return new F(arguments);
};
addProto(f, prototype);
for (key in extend) {
value = extend[key];
f[key] = value;
}
return f;
};
module.exports = createBuilder;