0

i have some array, and inside array i want to define another array. Are those 2 definitions equal? many thanks :)

args: [{
    key: "data",
    ajaxOptions: {
        url: '/rest/adrestresource/1.0/activedirectory/findgroups%[email protected]%20Bezhesla1%20localhost%20CN=Builtin,DC=lab,DC=local',
        type: "GET",
        dataType: "xml"
    }
}];

args: function () {
    return [{
        key: "data",
        ajaxOptions: {
            url: '/rest/adrestresource/1.0/activedirectory/findgroups%[email protected]%20Bezhesla1%20localhost%20CN=Builtin,DC=lab,DC=local',
            type: "GET",
            dataType: "xml"
        }
    }];
}

It is used for configuring a gadget, documentation says: Either an array of objects or a function that returns one. T First approach is working correctly, but defining array by function returning it is not working :?

4
  • 1
    the first one shouldn't have a semicolon at the end Commented Jun 14, 2013 at 7:49
  • You want to use getters and setters: developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/… Commented Jun 14, 2013 at 7:49
  • The second one needs to be called as a function => args() Commented Jun 14, 2013 at 7:49
  • That's confusing documentation, if it accepts function then it means exactly what you are doing. And calling args: function(){return ['blah']}() is really not passing a function. it's passing a value that the function returns. Commented Jun 14, 2013 at 8:19

1 Answer 1

2

The first example you have a property that is an array. The second example, it is a method that returns an array, so call it like:

// example 1
var myArray = Something.args; // property

// example 2
var myArray = Something.args(); // method
Sign up to request clarification or add additional context in comments.

2 Comments

It could be args: (function () {return[]})() to return an array
ty Edorka, that is exactly what i needed :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.