I guess you want to write something like
if (State.STATE_A === someState) { ... }
You could simply define another layer in your State object like
var State = { STATE_A : 0 STATE_B : { B1 : 1, B2 : 2, } }; ... if (State.STATE_B.B1 == someState){...}
Edit: Based on the comments on your question another approach could be this.
//Creates state objects from you json. function createStates(json) { var result = {}; for(var key in json) { result[key] = new State(json[key]); } return result; } //State class function State(value) { //If the state value is an atomic type, we can do a simple comparison. if (typeof value !== "object") { this.value = value; this.check = function(comp){ return value === comp; }; } // Or else we have more substates and need to check all substates else if (typeof value === "object") { this.value = createStates(value); for(var key in this.value) { //Allows to access StateA.SubStateA1. Could really mess things up :( this[key] = this.value[key]; } this.check = function(comp){ for(var key in this.value) { if (this.value[key].check(comp) === true){ return true; } } return false; }; } };
Now you can call everything with
var stateJson = { STATE_A : 0, STATE_B : { B1 : 1, B2 : 2 } }; var states = createStates(stateJson); alert(states.stateA.check(0)); // Should give true alert(states.STATE_B.B1.check(1)); // Same here alert(states.STATE_B.check(1)); //And again because value is valid for one of the substates.