Rules for JavaScript Library developers

Source: Internet
Author: User
Tags foreach html tags new features

Core tips: Rules for JavaScript Library developers

1. Keep Non-invasive 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 entirely against it. Objects are the basic building blocks of JavaScript functionality and don't mess with them.

3. Don't overdo the expansion of JavaScript-built objects as little as possible. Don't misunderstand what I mean. JavaScript's native objects are a bit less useful, and sometimes have to add one or two of their own methods. But 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 objects, the less likely it is that 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 ability of programming language. Remember, JavaScript and Dom are constantly being normalized. If you want to "fix" something, it is best to see if it has been corrected and consider the existing solution. If you follow the standard, follow the criteria tightly (i.e., do not omit a parameter of the Foreach method).

5. Or follow the lead Mozilla to lead JavaScript. The creator of the JavaScript language, Brendan Eich, is continuing to develop. These new language features are first available in Mozilla browsers, compared to other browsers. If you want to add new language features to JavaScript, you can look at the Mozilla standard first. For example, if you want to extend an enumeration method to an array object, it is best to name the method foreach instead of each. If you do want to provide a language feature that does not yet exist, follow the existing standards (refer to the example above).

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

7. Manage memory you need to do your best to worry about memory leaks.

8. Eliminate browser sniffing looks like browser vendors will always compete by adding new features;- As a library developer, you need to keep abreast of the latest trends. Browsing the Ajaxian once in a while is not enough, you have to read every blog post to find the next hack in a slave-like manner. Browsers can be addicted to sniffing.

9. A small and better variety of JavaScript libraries are ripe. Some libraries have been applied to mainstream websites. But not everyone has 2MBit of DSL bandwidth, so keep your library small. A better approach would be to provide a packaged page that allows you to effectively build your own library to my needs.

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

11. Additional Rules
Documents that are annoying but absolutely necessary to do.
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 who will execute your code.



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.