JavaScript “map” Function
问题 Looking at the map function in JavaScript, what am I doing wrong here? // input: [{name: "Kevin"}, {name: "Bob"}]; // output: [{"Kevin" : 0}, {"Bob" : 1}]; var map = function(arr, property) { var i = 0; var m = arr.prototype.map(makeKv); // input: {name: "Kevin"} // output: {"Kevin" = i} // GLOBAL function makeKv(item) { return {item: i++}; }; console.log("m : " + m); } http://jsfiddle.net/FgdSj/2 Also, if you could help please me get rid of the global too. 回答1: There are a few issues here: