这可能太简单了,但对象语法正在向我发展。
我有一个简单的函数,它返回一个非常适合在对象上用作参数的字符串,所以:
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"
});
我知道我不能只在那里抛出函数,也不能将它存储在变量中并插入,所以,我如何输入该字符串,好像它实际上是对象的一部分?
答案 0 :(得分:2)
只需将其内联:
new myPlayer({
this: "#that",
css: "#theOther",
theString: createString(),
other: "nana",
things: "yeah",
around: "yeahyeah"
});
答案 1 :(得分:2)
new myPlayer({
this: "#that",
css: "#theOther",
string: createString(),
other: "nana",
things: "yeah",
around: "yeahyeah"
});