Created
December 1, 2013 12:13
-
-
Save mateuszkocz/7732912 to your computer and use it in GitHub Desktop.
Safe 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 Constructor = function() { | |
if (!(this instanceof Constructor)) { | |
return new Constructor(); | |
} | |
// Properties and methods... | |
this.something = 'something'; | |
// ... | |
} | |
var object1 = new Constructor(), | |
object2 = Constructor(); | |
console.log(object1.something); // 'something' | |
console.log(object2.something); // 'something' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment