0

I'm trying to assign myShuttle.command to a string called signIn which is being stored in the shuttleCommands function.

function buildAndLaunchSignInShuttle (credentialsDoc) {
    var myShuttle = new shuttle();
    myShuttle.command = shuttleCommands.signIn;
    myShuttle.document = credentialsDoc;
    var responseObject = server.launchShuttle(myShuttle);

    return responseObject;
}

function shuttleCommands() {
    return {
        signIn: "signIn",
        signOut: "signOut",
        getEntireCollection: "getEntireCollection",
        getSingleDocument: "getSingleDocument",
        saveDocument: "saveDocument"
    };
}

How do I go about doing this? I don't really know what the right way of phrasing this is which is hindering my Googling!

3
  • shuttleCommands is a function. Drop the function ceremony and make it an object literal. Commented Mar 6, 2015 at 20:29
  • You have to run shuttleCommands first... shuttleCommands is a function. You have to run it for it to return the object with what you're trying to get. Commented Mar 6, 2015 at 20:31
  • Can you give a code example of what you mean? Commented Mar 6, 2015 at 21:48

1 Answer 1

1
myShuttle.command = shuttleCommands.signIn;

This will assign myShuttle.command to the signIn attribute of the shuttleCommands function itself, which is probably undefined.

I think you want to assign myShuttle.command to the signIn attribute of the value returned by the shuttleCommands function, which would be

myShuttle.command = shuttleCommands().signIn;
Sign up to request clarification or add additional context in comments.

5 Comments

Yup, this is what should happen.
At first look I thought that was the ticket but I'm getting a TypeError: object is not a function error. It was a global variable before but I want to wrap it in a function to stop it being global.
If shuttleCommands isn't a function, what is it? You might want to learn to use the browser's debugger.
It's exactly as I've put it above, which is a function as far as I can tell.
Your computer has a different opinion, and it is usually well-informed about such things. Investigate with the debugger.

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.