Anonymous Functions
© 2008 Haim Michael Introduction
An anonymous function is a function without a name. We can create an anonymous function by creating a function expression and assigning it to a variable.
The function expression is the anonymous function. ... var ob = function(numA,numB) { return numA+numB; }; ...
© 2008 Haim Michael Introduction
© 2008 Haim Michael Recursive Functions
When developing an anonymous function we can use the callee function in order to implement recursion.
© 2008 Haim Michael Recursive Functions
© 2008 Haim Michael Closures
Closure is the combination of a function bundled together (enclosed) with reference to its surrounding state (the lexical environment).
In JavaScript, we create a closure whenever we define a function. When we define a function within another function then the inner function will hold a reference to the local variables of the outer one as well as to all the global variables.
© 2008 Haim Michael Closures
© 2008 Haim Michael Closures
Using closures might be a bit tricky. The closure always gets the last value of any variable from the enclosed function.
© 2008 Haim Michael Closures
© 2008 Haim Michael The this Keyword
Using this within a method called on a specific object this points at the object on which the method was called.
Using this within a global function this points at the Window object.
Using this within the scope of a closure points at the Window object as well.
© 2008 Haim Michael The this Keyword
© 2008 Haim Michael