Javascript namespace to improve code reusability _ javascript skills
Source: Internet
Author: User
Add namespaces to your encapsulated javascript library to improve code reusability. After more than 10 js files are introduced to the same web page,
Functions with the same name in each js are prone to conflicts.
For example, the addCssStyle method is written in the xxx library,
The yyy Library also writes an addCssStyle method,
The specific implementation of these two methods is different.
When these two components are referenced at the same time, the page effect changes after a function conflict occurs,
Debugging and modification are both very painful. To avoid conflicts,
It is even more depressing to give up Referencing some excellent components.
Therefore, when encapsulating javascript Component Libraries, use namespaces to avoid conflicts.
All methods and variables must be written according to the class name of the package name.
(Writing code is as convenient as encapsulating java's util method)
As a result, my js library is encapsulated as follows.
After google for half a day, there was no ready-made product, so I found out it myself. The sample code is as follows:
(Lizongbo original !!!)
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.