JSFiddle - React, Tailwind, and code Playground
by Alex Baumgertner
JavaScript
var roles = {
anonymous: { value: 0, toString: function () { return "anonymous"; } },
authenticated: { value: 1, toString: function () { return "authenticated"; } },
locked: { value: 2, toString: function () { return "locked"; } },
fromInt: function (value) {
switch (value) {
case 0:
return Object.create(this.anonymous);
break;
case 1:
return Object.create(this.authenticated);
break;
case 2:
return Object.create(this.locked);
break;
}
}
};
userARole = roles.fromInt(0);
userBRole = roles.fromInt(0);
console.log(userARole == userBRole.toString());
console.log(userARole === userBRole);