1

I need to access a sibling object within and object.

I have tried the following but it does not work

var obj = {
    settings: {
        container: $('#agrid')
    },
    columns: settings.container.data('columns'),
    rows: settings.container.data('rows'),
}

I have also tried

var obj = {
    settings: {
        container: $('#agrid')
    },
    columns: this.settings.container.data('columns'),
    rows: this.settings.container.data('rows'),
}

But it does not work either.

UPDATE

I currently do it this way, but since the columns and row, values does not change I would like to be a static value istead of a function.

var s,
    aGrid = {

        settings: {
            container: $('#agrid')
        },

        init: function () {
            s = this.settings;
        },

        getColumns: function () {
            return s.container.data('agrid-columns');
        },

        getRows: function () {
            return s.container.data('agrid-rows');
        },

    };

aGrid.init();

The html is just the following.

<div id="agrid" data-agrid-rows="3" data-agrid-columns="6">

</div>
Rasmus Nørskov
  • 478
  • 1
  • 6
  • 20
  • 1
    Could you show us your HTML? How do you write the `#agrid` ? – naota Jul 07 '14 at 23:41
  • @naota The contents of the HTML are irrelevant, this could be pure javascript and its still not possible. –  Jul 07 '14 at 23:45

1 Answers1

2

That's not possible during object instantiation.

You can assign it after the obj exists, but not before:

var obj = {
    settings: {
        container: $('#agrid')
    },
};
obj.columns: obj.settings.container.data('columns');
obj.rows: obj.settings.container.data('rows');