4 回答
TA贡献1797条经验 获得超6个赞
function processArray(arr, callback) { var resultArr = new Array(); for (var i = arr.length-1; i >= 0; i--) resultArr[i] = callback(arr[i]); return resultArr; } var arr = [1, 2, 3, 4]; var arrReturned = processArray(arr, function(arg) {return arg * -1;}); // arrReturned would be [-1, -2, -3, -4]
TA贡献1946条经验 获得超4个赞
fileObject = open(file) # now that we have WAITED for the file to open, we can write to it fileObject.write("We are writing to the file.") # now we can continue doing the other, totally unrelated things our program does
# we pass writeToFile (A CALLBACK FUNCTION!) to the open function fileObject = open(file, writeToFile) # execution continues flowing -- we don't wait for the file to be opened # ONCE the file is opened we write to it, but while we wait WE CAN DO OTHER THINGS!
- 4 回答
- 0 关注
- 406 浏览
添加回答
举报