There really is no way that I could have specific values ββfor the role, but maybe you need to create several types of objects based on the type of the main object, each with its own roles (and something else you want to distinguish). For example...
var userSchema = function userSchema() {}; userSchema.prototype = { email: String, password: String, role: undefined } var member = function member() {}; member.prototype = new userSchema(); member.prototype.role = 'member'; var notSupposedToBeUsed = new userSchema(); var billTheMember = new member(); console.log(notSupposedToBeUsed.role);
Another possibility is to have userSchema with a constructor that easily allows you to select one of the built-in values. Example...
var userSchema = function userSchema(role) { this.role = this.role[role]; // Gets the value in userSchema.role based off of the parameter }; userSchema.prototype = { email: String, password: String, role: { admin: 'admin', member: 'member', guest: 'guest' } } var a = new userSchema('admin'); var b = new userSchema('blah'); console.log(a.role); // 'admin' console.log(b.role); // undefined
More details: http://pivotallabs.com/users/pjaros/blog/articles/1368-javascript-constructors-prototypes-and-the-new-keyword
Pluto
source share