Skip to content

Instantly share code, notes, and snippets.

@liunian
Created May 30, 2013 07:24
Show Gist options
  • Save liunian/5676234 to your computer and use it in GitHub Desktop.
Save liunian/5676234 to your computer and use it in GitHub Desktop.
jquery 和 underscore 式的构造器,有无 new 都会进行创建,传入已创建的对象会直接返回
var _ = function(obj) {
if (obj instanceof _) return obj;
if (!(this instanceof _)) return new _(obj);
this._wrapped = obj;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment