有沒有更簡潔的寫法呢?JavaScript:功能映射?
var me = {};
for (var i in you) {
me[i] = you[i];
}
(其中you
是任意-lengthed JavaScript數組)
換句話說,給定的輸入:
var you = [
"what",
"r",
"u"
];
輸出,me
,變爲:
me = {
0: "what",
1: "r",
2: "u"
};
像,使用一些功能方法的單線?
實際上你的榜樣會給`我= {0: 「什麼」,1: 「R」,2: 「U」 ,長度:3/*和Array的原型* /};` – tobyodavies 2011-02-01 04:37:12
因爲您要求[「功能性JavaScript」](http://osteele.com/sources/javascript/functional/)... :) – 2011-02-01 06:48:21