Unfortunately, you can't do that. This is because the properties of menuSetup
haven't been defined yet. For example,
var menuSetup = {
m: [100, 200],
height: menuSetup.m[0]
};
will through (in chrome) TypeError: Cannot read property 'm' of undefined
because menuSetup
is just undefined (because it was hoisted by the var
declaration)
The only two ways I can think of is to
a) Save m
as a variable before. For example:
var m = [100, 200];
var menuSetup = {
m: m,
height: m[0]
}
b) Use a method instead of a variable and execute it.
var menuSetup = {
m: [100, 200],
height: function() { return this.m[0]; }
}
Then, when you get menuSetup.height
, you would actually do menuSetup.height()
.