so I have an object definition that looks like this:
var Foo = window.Foo = {
MIN_ROWS : 10,
MIN_COLS : 10,
NUM_ROWS : (function(){ return Math.max( parseInt(this.params.rows) || 0, this.MIN_ROWS); })(),
// etc...
params: (function(){ /* ... */ })() // parses the GET querystring parameters from the URL and returns as a JSON object
}
For the NUM_ROWS property, I want to set it to be Foo.params.rows if it exists and it's greater than MIN_ROWS, otherwise set it to MIN_ROWS.
I've already figured out the logic for this, the only thing that's giving me trouble is when I self-invoke the function as above, the this variable refers to window and not to Foo as I would expect it to. (This is the error message I get in the console: "TypeError: Result of expression 'this.params' [undefined] is not an object." )
If I don't self-invoke the function, it works perfectly. However, I'd like to have NUM_ROWS be an integer, not a function, so that I can access it as Foo.NUM_ROWS and not Foo.NUM_ROWS() in the other parts of my code.
Can anyone help me out with this please?