Actually there is not much difference if it is not done much. An anonymous function will use a slightly inconsequential amount of memory than a separate function.
The reason is that the declaration of an individual function will be used essentially as a pointer so that it can be reused. However, an anonymous function will need to be created each time. This is a very small difference.
The main difference is the definition of the area and parameters. You cannot pass parameters to a function pointer. Is a function inside a timeout required to exchange an area with a parent? If so, then an anonymous function may be more worthwhile than a declared function in another area. General - pass this .
var that = this; window.setTimeout(function(){
To send a message, for example, if your notification was function showAlert(msg) , you will need to use the anonymous function window.setTimeout(function(){showAlert("hello");}, 2000); .
What you really want to avoid is a string. For example,
window.setTimeout("slowAlert()", 2000);
This is considered bad practice because the function will be built on the basis of a string similar to using eval .
Travis j
source share