Skip to content

Instantly share code, notes, and snippets.

@Williammer
Created July 3, 2014 09:06
Show Gist options
  • Select an option

  • Save Williammer/13c19c4a45cc505d1177 to your computer and use it in GitHub Desktop.

Select an option

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.
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