Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There isn't really a way that I know of to have specific values possible for role, but maybe you'd like to create multiple object types based off of a master object type, each with their own roles (and anything else you want to distinguish). For example...</p> <pre><code>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); // undefined console.log(billTheMember.role); // member </code></pre> <p>Another possibility is have userSchema with a constructor that easily allows you to select one of the built in values. An example...</p> <pre><code>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 </code></pre> <p>More: <a href="http://pivotallabs.com/users/pjaros/blog/articles/1368-javascript-constructors-prototypes-and-the-new-keyword" rel="nofollow">http://pivotallabs.com/users/pjaros/blog/articles/1368-javascript-constructors-prototypes-and-the-new-keyword</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload