這可能太簡單了,但對象語法正在接近我。在javascript中的一個新對象中使用返回值
我有一個簡單的函數,返回一個字符串非常適合使用作爲參數的對象,所以:
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"
});
我知道我不能只是拋出函數那裏,既不存儲它在一個變量和插入,所以,我怎麼去輸入該字符串,就好像它實際上是對象的一部分?
你必須更具體一些,提供一個更好的例子。 'newPlayer'是一個函數,似乎你想傳遞三個參數給它。我不明白「對象」部分。你想'新的myPlayer({...},createString(),{...})'? **是什麼**'myPerfectstring'? – 2012-03-09 18:12:34
按照約瑟夫西爾伯和科學家的說法,或者看看這個小提琴:http://jsfiddle.net/MQND7/ – jack 2012-03-09 18:16:16