Asynchronous programming in TypeScript
Now that we have seen how to work with functions, we will explore how we can use them, together with some native objects, to write asynchronous applications.
Callbacks and higher-order functions
In TypeScript, functions can be passed as arguments to another function. The function passed to another as an argument is known as a callback. Functions can also be returned by another function. The functions that accept functions as parameters (callbacks) or return functions as an argument are known as higher-order functions. Callbacks are usually anonymous functions.
var foo = function() { // callback console.log('foo'); } function bar(cb : () => void) { // higher order function console.log('bar'); cb(); } bar(foo); ...
Get TypeScript: Modern JavaScript Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.