Closure
29-12-2015 16:58:54
JQuery / Common
0 Bookmark(s)
174 View(s)
If you define a function in JavaScript, it will be added to the 'global space' which means, that it is visible for everyone. If someone else (e.g. a library) defines a function with the same name, it would override your function. Therefore it is not good design to put things to the global space.
To hide functions you can define them in a closure, which is like an isolated scope that is not visible from external. In JavaScript this can be achieved with a self executing anonymous function:
(function(){
// Your code goes here...
})();