Created
January 15, 2014 17:19
-
-
Save jinqian/8440374 to your computer and use it in GitHub Desktop.
a very clean way to make sure your object is called as a constructor !
This file contains hidden or 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 Lawnchair = function (options, callback) { | |
| // ensure Lawnchair was called as a constructor | |
| if (!(this instanceof Lawnchair)) return new Lawnchair(options, callback); | |
| // ... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment