0

This is probably too simple, but the object syntax is getting to me.

I have a simple function, that returns a string perfectly fit for using as arguments on an object, so:

function createString() {

// yadda yadda yadda

    return myPerfectstring;
}

and then there's this object, which should take myPerfectstring as a value like this:

new myPlayer({
        this: "#that",
        css: "#theOther"
    },
        //  insert myPerfectstring here
        // if I log it to the console and copy-paste here, everything works wonders
    , {
        other: "nana",
        things: "yeah",
        around: "yeahyeah"
    });

i know i can't just throw the function there, neither store it in a variable and insert, so, how do i go about entering that string as if it were really part of the object?

2
  • You have to be more concrete, provide a better example. newPlayer is a function and seems you want to pass three arguments to it. I don't understand the "object" part. Do you want new myPlayer({...}, createString(), {...})? What is myPerfectstring? Commented Mar 9, 2012 at 18:12
  • Do as Joseph Silber and thescientist says, or take a look at this fiddle: jsfiddle.net/MQND7 Commented Mar 9, 2012 at 18:16

2 Answers 2

2

you can't do this? I'm having trouble determing how you are trying use the return value within the constructor. as it's own property?

new myPlayer({
  this: "#that",
  css: "#theOther",
  string: createString(),
  other: "nana",
  things: "yeah",
  around: "yeahyeah"
});
Sign up to request clarification or add additional context in comments.

1 Comment

this did it. Actually it was what i was trying to do from the beginning, but i didn't know the object would only take an array, not a string, and that's why it wasn't working and i thought using the function also wasn't.
2

Just put it inline:

new myPlayer({
        this: "#that",
        css: "#theOther",
        theString: createString(),
        other: "nana",
        things: "yeah",
        around: "yeahyeah"
    });

Comments

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.