在javascript中的新对象内使用返回值

在javascript中的新对象内使用返回值,javascript,Javascript,这可能太简单了,但对象语法让我感到困惑 我有一个简单的函数,它返回一个非常适合用作对象参数的字符串,因此: function createString() { // yadda yadda yadda return myPerfectstring; } 然后是这个对象,它应该将myPerfectstring作为如下值: new myPlayer({ this: "#that", css: "#theOther" }, //

这可能太简单了,但对象语法让我感到困惑

我有一个简单的函数,它返回一个非常适合用作对象参数的字符串,因此:

function createString() {

// yadda yadda yadda

    return myPerfectstring;
}
然后是这个对象,它应该将
myPerfectstring
作为如下值:

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"
    });
我知道我不能直接将函数扔到那里,也不能将其存储在变量中并插入,那么,如何才能像输入对象的一部分那样输入字符串呢?

只需将其内联:

new myPlayer({
        this: "#that",
        css: "#theOther",
        theString: createString(),
        other: "nana",
        things: "yeah",
        around: "yeahyeah"
    });
只需将其内联:

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

你不能这么做?我无法确定如何在构造函数中使用返回值。因为它是自己的财产

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

你不能这么做?我无法确定如何在构造函数中使用返回值。因为它是自己的财产

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

你必须更具体,提供一个更好的例子
newPlayer
是一个函数,您似乎希望向它传递三个参数。我不理解“对象”部分。是否要
新建myPlayer({…},createString(),{…})
?什么是
myPerfectstring
?按照Joseph Silber和这位科学家所说的去做,或者看看这把小提琴:你必须更具体,提供一个更好的例子
newPlayer
是一个函数,您似乎希望向它传递三个参数。我不理解“对象”部分。是否要
新建myPlayer({…},createString(),{…})
?什么是
myPerfectstring
?按照Joseph Silber和这位科学家所说的去做,或者看看这把小提琴:就是它。实际上,这是我从一开始就想做的,但我不知道对象只接受数组,而不是字符串,这就是为什么它不起作用,我认为使用函数也不起作用。这就成功了。实际上,这是我从一开始就想做的,但我不知道对象只接受数组,而不是字符串,这就是为什么它不起作用,我认为使用函数也不起作用。