6

I am trying this:

return {
    configs: app.config
}

But it does not seem to work. Is there another way to return an anonymous object with the one field "configs" ?

Samantha J T Star
  • 30,952
  • 84
  • 245
  • 427
  • 1
    possible duplicate of [JavaScript: function returning an object](http://stackoverflow.com/questions/12272239/javascript-function-returning-an-object) – Raptor Jun 04 '14 at 02:40
  • 3
    "It does not seem to work". What does it return? Undefined? An empty object? Does it error? Barring more information, and assuming you're putting in a copy/paste, you'll need to surround "app.config" with quotes, to make it a string. – Knetic Jun 04 '14 at 02:41
  • You can't have a `return` statement outside of a function. There is nowhere to "return" to. – Felix Kling Jun 04 '14 at 02:42
  • The return statement is in a function. When I try to look at the .configs value of what's returned it gives undefined. – Samantha J T Star Jun 04 '14 at 02:42
  • 3
    Samantha: then please post the *whole of the relevant code* (because as you've written it, and assuming no errors in the parts we can't see, I would think that *should* work). – David Thomas Jun 04 '14 at 02:43

1 Answers1

10
function someFunc() {
    var retVal = {
        configs: app.config
    };
    return retVal;
}

Here is another idea:

var someFunc2 = function() { 
    var app = {};
    app.config = 1;
    return { configs: app.config };
};
someFunc2();
// Object {configs: 1}
Jess
  • 23,901
  • 21
  • 124
  • 145