2

I'm creating a Grid object using the following code:

var Grid = { rows: 5, cols: 6, getDimensions: function() { console.log(rows + ' by ' + cols); }(), }; 

My getDimensions function isn't working however because it cannot reference the rows and cols properties that I previously set. this is set to the window so I'm not sure how I would reference these properties.

1 Answer 1

5
var Grid = { rows: 5, cols: 6, getDimensions: function() { console.log(this.rows + ' by ' + this.cols); }(), }; 

Use this to reference other properties of the object. Keep scope in mind. Alternatively you can use Grid.rows and Grid.cols

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.