What are the main advantages of adding your custom functions to a javascript libraries namepsace?
- by yaya3
It is fairly well known in JavaScript that declaring variables within the global scope is a bad thing. So code I tend to work on contains namespaced JavaScript.
There seems to be two different approaches taken to this -
Adding your application specific functions to the libraries' namespace e.g. $.myCarouselfunction
Creating your own namespace e.g. MyApplication.myCarouselFunction
I wanted to know whether or not there is a 'better' solution or if they tend to meet somewhere close in terms of pros and cons.
The reason for me personally deciding not to go with the library is for Seperation / Isolation / Lack of conflict with library code and potential plugins that are likely to share that namespace. But I am sure there is more to this.
Thanks