Abstract-JavaScript is a popular language for developing web applications and is increasingly used for both client-side and server-side application logic. The JavaScript runtime is inherently event-driven and callbacks are a key language feature. Unfortunately, callbacks induce a non-linear control flow and can be deferred to execute asynchronously, declared anonymously, and may be nested to arbitrary levels. All of these features make callbacks difficult to understand and maintain. We perform an empirical study to characterize JavaScript callback usage across a representative corpus of 138 JavaScript programs, with over 5 million lines of JavaScript code. We find that on average, every 10th function definition takes a callback argument, and that over 43% of all callback-accepting function callsites are anonymous. Furthermore, the majority of callbacks are nested, more than half of all callbacks are asynchronous, and asynchronous callbacks, on average, appear more frequently in client-side code (72%) than server-side (55%). We also study three well-known solutions designed to help with the complexities associated with callbacks, including the errorfirst callback convention, Async.js library, and Promises. Our results inform the design of future JavaScript analysis and code comprehension tools.
Another empirical study was done to analyze JavaScript callback usage as callbacks induces non-linear control flow of program and can cause asynchronous execution REF .
Don't Call Us, We'll Call You: Characterizing Callbacks in Javascript
2015 ACM/IEEE International Symposium on Empirical Software Engineering and Measurement (ESEM)
2015 ACM/IEEE International Symposium on Empirical Software Engineering and Measurement (ESEM)
Computer Science