Created
May 30, 2013 07:24
-
-
Save liunian/5676234 to your computer and use it in GitHub Desktop.
jquery 和 underscore 式的构造器,有无 new 都会进行创建,传入已创建的对象会直接返回
This file contains 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 _ = 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