我正在使用一個函數,它需要一個回調參數來傳遞我自己的函數。然而,我發現了錯誤function expected
Javascript Foreach Function Expected
GpsGate.Server.MyService.getTracksByUser(groupName, user.username, getTracksByUser_callback());
function getTracksByUser_callback(result)
{
var responseData = '<response>';
result.tracks.foreach(//error on this line
function addTrack(track) {
responseData += '<track>';
//ommited
responseData += '</track>';
}
);
responseData += '</response>';
response.body = responseData;
}
看例子http://msdn.microsoft.com/en-us/library/ie/ff679980(v=vs.94).aspx IM不能確定爲什麼它不工作
'results.tracks.foreach'不是函數。如果它應該是一個數組,它應該是[forEach](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach) – 2014-09-29 18:16:57
確保發佈*完整的*錯誤信息和將來的上下文。 – user2864740 2014-09-29 18:24:21