Created
July 3, 2014 09:06
-
-
Save Williammer/13c19c4a45cc505d1177 to your computer and use it in GitHub Desktop.
jsBasic.secureConstructorFn.js - defensively check the existence of the instantiate of constructor function to avoid calling it as function.
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
| if (typeof Object.create === "undefined") { | |
| Object.create = function (prototype) { | |
| function C() {} | |
| C.prototype = prototype; | |
| return new C(); | |
| }; | |
| } | |
| function User(name, passwordHash) { | |
| var self = this instanceof User ? this : Object.create(User.prototype); | |
| self.name = name; | |
| self.passwordHash = passwordHash; | |
| return self; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment