0

Hi I seem to be having problems executing a function deep within arrays:

var Segments = [Segment_1];

var Segment_1 = {
  "requirements": {
    "Dektec": "True",
    "SSH": "True"
  },
  "requests": {
    "R11": "True"
  },
  'function': function(){
     print("Hello World!");
  }
};


Segments[0]['function']();

This works if I am only one array deep though:

var Segments = [Segment_1];

function Segment_1() {
    print("Hello World!");
}

Segments[0]();

I have seen similar questions in Stackoverflow, but all pertaining to single level array. Any idea to what I am doing wrong here? I'm sure it is something simple.

Thanks

4

1 回答 1

3

You need to set Segments after you set Segment_1

var Segment_1 = {
    "requirements": {
        "Dektec": "True",
        "SSH": "True"
    },
    "requests": {
        "R11": "True"
    },
    'function': function(){
        document.write("Hello World!");
    }
};

var Segments = [Segment_1]

You set Segments before you define Segment_1, therefore it is undefined.

于 2013-03-22T17:55:52.490 回答