Use the JavaScript library or write your own code?

Source: Internet
Author: User

You must decide which of the two methods to write your JavaScript code. To help you make a wise decision which is more suitable for you, we will compare the advantages and disadvantages of the two methods.

One disadvantage of using JavaScript libraries in the past is that libraries are often quite large, and may include a lot of code that is not actually used on your personal web pages. Perhaps writing your own code can be considered the most effective way to fully meet your real needs, and there are no other methods that are more effective than this. However, after introducing a general repository of Google, everyone can use the popular JavaScript library through links, because if you are linking to a Google database copy instead of using your own copy, a large number of visitors will have libraries that have been buffered on their browsers, the download is only part of the code on your page. By doing so, you can use it faster than your own library.

One advantage of writing code by yourself rather than relying on libraries is that you don't have to learn much. To be able to write JavaScript, you only need to learn JavaScript. To be able to use the library, you need to learn JavaScript and the Library at the same time. You may be able to do something like this. You only learn the library but haven't learned JavaScript, but you can use this library in the best way, you will need to have a better understanding of JavaScript than the typical users who just use JavaScript to write their own code.

The advantage of using the database is that the database has processed 90% of the operations you need to run, which means you only need to write the remaining 10%. When there is a lot of code writing, this can save you time writing the code. In addition to writing code and testing it, it may or may not save time, unless you have a deep understanding of how to make the library you selected do what you should do during the test time, using the library may eventually be much longer than writing your own code.

Another thing you need to consider is how much code is included in a given library that you will actually need to use to achieve your goal, and whether the library includes all the operations you want. If you cannot find a library that has all the functions you need, you need to write the remaining code or try to introduce the second library that includes the missing functions. Depending on how the library works, two libraries may or may not be used simultaneously on the same web page.

In fact, before you consider using a library, how much JavaScript code you need to write will also affect your decision. If you have already written your own code to execute the processing of all the different functions you need, it is possible that you choose a library that provides all the same functions but achieves different methods. Since the people who write these libraries first generally have a deep understanding of JavaScript, one reasonable possibility you must admit is, A library that provides these features is more efficient than what you write (unless you have a JavaScript expert ).

What type of JavaScript processing you want to add to the webpage will also affect whether the library is suitable for use. If you only need a few lines of JavaScript code to send a small special effect to Your webpage, it is better than writing all the code from the user, using a library may cause you to have to write more code as an interface to implement library work. Of course, in turn, it also adapts. If you want to add a large number of processes to your web page and closely match the function type of the library you selected, the database can be processed for you.

Selecting a function is closely consistent with the library you want to use on your web page and a good understanding of JavaScript and the library, you can quickly and easily add all the features you want, this modern, non-abrupt approach may be the most suitable method for you. In addition, if you have been writing JavaScript for many years and have your code library that can execute most of the features you constantly require, then you don't have to select or learn any database to achieve the same effect.

Personal Summary

I personally think that Stephen Chapman's article compares the advantages and disadvantages of the JavaScript library and self-writing code. In fact, if you can make full use of it when using the JavaScript library, to realize the value it deserves, the JavaScript library will be a good tool, a tool that creates rich clients and brings users a good experience, instead of being an extra burden for loading pages. For those who like self-writing code, I think it is also necessary to encapsulate some functions, such as DOM operations and event processing, after all, native JavaScript has many compatibility and efficiency problems in different browsers (refer to the JavaScript layering concept of ADAM). At the same time, I also think that if you are using a popular JavaScript Library (such as jQuery, YUI, and Ext JS), you can understand the implementation mechanisms of these libraries, in this way, we can better control these databases!



Translated by genevich (Chinese). If you have any reprinted documents, please indicate the source. If any translation has any mistakes, please leave a message to indicate

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.