What are the main advantages of adding your custom functions to a javascript libraries namepsace?
Posted
by yaya3
on Stack Overflow
See other posts from Stack Overflow
or by yaya3
Published on 2010-06-13T23:13:53Z
Indexed on
2010/06/13
23:22 UTC
Read the original article
Hit count: 282
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
© Stack Overflow or respective owner