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 關注
- 460 瀏覽
添加回答
舉報
