moraleida
moraleida

Reputation: 424

using a return value inside a new object in javascript

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?

Upvotes: 0

Views: 75

Answers (2)

thescientist
thescientist

Reputation: 2948

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"
});

Upvotes: 2

Joseph Silber
Joseph Silber

Reputation: 219938

Just put it inline:

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

Upvotes: 2

Related Questions