1. Remain non-invasiveMy HTML tags don't want to know your JavaScript code.
2. Modification and extension of object.prototype! is strictly prohibitedThis 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. Do not extend too muchThe fewer extensions to JavaScript-built objects, the better. 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 standardAs a library ofDevelopment, 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 leadMozilla leads the JavaScript. The creator of the JavaScript language, Brendan Eich, is continuingDevelopment。 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 flexibleIf 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 MemoryYou should try your best to worry about the memory leak.
8. Eliminate browser sniffingIt seems that browser vendors will always compete by adding new features;- As a library ofDevelopment, you have 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. Smaller and betterVarious 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.