0

How to get types.type1["color"] from below? I mean how to write public method to get it.

Config = (function(){

var ids = {
      id1: "id1",
      id2: "id2",
      ....
  }
var types = {
       type1: {
               "color": "red",
               "size": "10"
                ...
              },
        type2: {
               "color": "red",
               "size": "40"
            }
      }
  return {
      getIds: function(id){
            return ids[id];
       }
      getTypes: function(type){
             return types[type];
       }

 }
}();
3
  • you have a ending "missing, after "size": "40 Commented Jun 28, 2013 at 4:25
  • Config.getTypes("type1")["color"]? Commented Jun 28, 2013 at 4:29
  • 3
    add to that missing ) on last line. Commented Jun 28, 2013 at 4:30

2 Answers 2

6
Config.getTypes("type1").color

Using:

Config = (function(){
    var ids = {
        id1: "id1",
        id2: "id2"
    };

    var types = {
        type1: {
            "color": "red",
            "size": "10"
        },
        type2: {
            "color": "red",
            "size": "40"
        }
    };

    return {
        getIds: function(id){
           return ids[id];
        },
        getTypes: function(type){
           return types[type];
        }
    };
})();
Sign up to request clarification or add additional context in comments.

Comments

1

Try

Config.getTypes("type1")["color"]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.