In depth analysis of functions mechanism in JS
Function are objects in JS and hence they have a prototype. The advantage of function being objects is that they can be easily passed as arguments to other functions or objects. There are 3 main methods in Function's prototype:
.call()
and.apply()
: they do significantly the same thing, ie executing a function while letting you specify a different 'this' than the natural one (that you pass in the first argument). The difference between the two is that arguments in addition tothis
are passed individually in.call()
and as an array in.apply()
.