FUNCTION INTERNALS
In ECMAScript 5, two special objects exist inside a function: arguments
and this
. In ECMAScript 6, the new.target
property was introduced.
arguments
The arguments
object, as discussed previously, is an array-like object that contains all of the arguments that were passed into the function. It is only available when a function is declared using the function
keyword (as opposed to arrow function declaration). Though its primary use is to represent function arguments, the arguments
object also has a property named callee
, which is a pointer to the function that owns the arguments
object. Consider the following classic factorial function:
function factorial(num) {
if (num <= 1) {
return 1;
} else {
return num * factorial(num - 1);
}
}
Factorial functions are typically defined to be recursive, as in this example, which works fine when the name of the function is set and won't be changed. However, the proper execution of this function is tightly coupled...