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" ?

5
  • 1
    possible duplicate of JavaScript: function returning an object Commented Jun 4, 2014 at 2: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. Commented Jun 4, 2014 at 2:41
  • You can't have a return statement outside of a function. There is nowhere to "return" to. Commented Jun 4, 2014 at 2:42
  • The return statement is in a function. When I try to look at the .configs value of what's returned it gives undefined. Commented Jun 4, 2014 at 2: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). Commented Jun 4, 2014 at 2:43

1 Answer 1

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}
Sign up to request clarification or add additional context in comments.

3 Comments

Why would that work and the OP's code not?
@Bergi This example worked for me in Chrome: x = function() { y = { config: 0}; return { configs: y.config}; } ; x();
@Bergi, I'm really not sure. Maybe a working example or a broader context?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.