underscore无new构造
学习underscore.js有感
(function () {
var root = this;
var _ = function(obj) {
if (obj instanceof _) return obj;
if (!(this instanceof _)) return new _(obj);
this._wrapped = obj;
};
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = _;
}
exports._ = _;
} else {
root._ = _;
}
_.fun = function (str) {
console.log(str)
}
_.prototype.fun = _.fun
}.call(this))
_.fun('fff')
var a = new _()
_.fun('aa')