When a function call is in tail position, ECMAScript 6 mandates that such a call must reuse the stack space of its own frame instead of pushing another frame onto the call stack. The return value of the called function is returned by the calling function.The calling function is not a generator function.The calling function is either a normal function or an arrow function.The calling function is in strict mode.A function call is in tail position if the following criteria are met: A call made to a function in tail position will reuse the stack space of the calling function. This data includes the return address, prior stack pointer, arguments to the function, and space for the function’s local values. Typically when calling a function, stack space is allocated for the data associated with making a function call. In deeply recursive code, PTC enables code to run that would otherwise throw a stack overflow exception. Through the use of PTC, the amount of memory needed to run code is reduced. Various other design patterns can benefit from PTC as well, such as code that wraps some functionality where the wrapping code directly returns the result of what it wraps. This feature was added to facilitate recursive programming patterns, both for direct and indirect recursion. Proper Tail Calls (PTC) is a new feature in the ECMAScript 6 language.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |