JavaScript Library developers ' rules

Source: Internet
Author: User

For more information, please click here.

1. Stay non-intrusive my HTML tags don't want to know your JavaScript code.

2. Modification and extension of object.prototype! is strictly prohibited. This is important and requires a rule that is completely against it. Objects are the basic building blocks of JavaScript functionality and don't mess with them.

3. Do not extend the extension to JavaScript built-in objects as little as possible. Don't get me wrong about what I mean. JavaScript's native objects are a bit less useful and sometimes have to add one or two of their own methods. However, for Creative (library) programmers, adding this "one or two" approach is not enough. However, please stop! Just add what you need. The fewer extensions you have to JavaScript built-in objects, the less likely your code will conflict with other frameworks.

4. Follow the standard as a library developer, you define the pattern of JavaScript code. Design pattern is the embodiment of weak programming language ability. Keep in mind that JavaScript and Dom are constantly being normalized. If you want to "fix" something, it's best to first see if it's been fixed and consider the existing solution. If you follow the standard, stick to the standard (e.g., don't omit one of the parameters of the Foreach method).

5. Or follow the lead Mozilla to lead JavaScript. The creator of the JavaScript language, Brendan Eich, continues to develop. These new language features are first available in Mozilla browser compared to other browsers. If you want to add new language features to JavaScript, you can look at the Mozilla standard first. For example, when you want to extend an enumeration method to an array object, it's best to name the method foreach instead of each. If you do want to provide language features that do not yet exist, follow the existing criteria closely (see the example above).

6. Be flexible if I want to change the behavior without changing your source code, is it easy? If it's not easy enough, make it easier.

7. Managing memory Everyone is worried about memory leaks and you have to do your best.

8. Eliminate browser sniffing it seems that browser vendors will always compete by adding new features;-) As a library developer, you need to keep up with the latest trends. It's not enough to visit Ajaxian once in a while, and you have to read every blog post in a slave-like manner to find the next hack. Browser sniffing is addictive.

9. A small and better variety of JavaScript libraries have matured. Some libraries are already being used on mainstream websites. But not everyone has 2MBit DSL bandwidth, so keep your library small. A better approach is to provide a packaged page that allows you to efficiently build your own library as I want.

10. Tenth rule good ol ' tenth rule (seems to be a colloquial usage, do not know how to translate well). You can always rely on the tenth rule. This is: keep it predictable. I should be able to guess what your method is for. If I don't know the name of a method, I should be able to guess.

11. Additional Rules
Documentation that is annoying but definitely needs to be done.
The more namespaces you use, the harder it is for me to remember, just like your phone number.
Remember: There may be millions of people that will execute your code.

Reference Source: http://www.ijavascript.cn/jiaocheng/javascript-library-rules-476.html

For more JavaScript content, click

JavaScript Library developers ' rules

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.