Skip to content

Instantly share code, notes, and snippets.

@scarvell
Created November 27, 2014 02:35
Show Gist options
  • Save scarvell/09cd5fa184739bdfe978 to your computer and use it in GitHub Desktop.
Save scarvell/09cd5fa184739bdfe978 to your computer and use it in GitHub Desktop.
function User (userData) {
this.id = userData.id;
this.firstName = userData.firstName;
this.lastName = userData.lastName;
this.displayName = this.firstName + " " + this.lastName;
this.email = userData.email;
this.admin = userData.admin || 0;
this.checkRights = function (code) {
if (this.isAdmin()) return true;
return (this.rights.split(',').indexOf(code)) ? true : false;
};
this.isAdmin = function () {
return (this.admin == 1) ? true : false;
}
}
var users = [
{firstName: 'Brendan', lastName: 'Scarvell', email: '[email protected]', admin: 1},
{firstName: 'Foo', lastName: 'Bar', email: '[email protected]', admin: 0},
{firstName: 'Chloe', lastName: 'Dog', email: '[email protected]', admin: 1},
];
users = users.map(function(u){ return new User(u); });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment