Use a JavaScript library or write your own code? _javascript Tips

Source: Internet
Author: User
You have to decide which of these two ways to write your JavaScript, and in order to help you make informed decisions about which is more appropriate for you, we will compare the pros and cons of these two methods.

One disadvantage of using JavaScript libraries in the past is that libraries tend to be quite large, perhaps including a lot of code that isn't actually used in your personal pages. Perhaps writing your own code can be considered the best way to fully meet your real needs, and there is no other way to do it. But when you introduce a generic repository for Google, everyone can use a link to the more popular JavaScript library, which is a denial, because if you link to a copy of Google's library, instead of using your own copy, Such a large number of visitors will have already buffered in their browser library, the actual download is only part of your page code. Doing so makes it quicker to use than the library you are doing.

One of the advantages of writing your own code rather than relying on libraries is that you don't have to learn too much. To be able to write JavaScript yourself, you just need to learn JavaScript. To be able to use a library, you need to learn both JavaScript and this library. You might be able to do things like this, just study the library and not learn JavaScript, but the best way to make use of this library, you will need more than those who just use JavaScript to write their own code of the typical people to have more knowledge of JavaScript.

The advantage of using a library is that the library has handled 90% of the operations you need to run, which means you only need to write the remaining 10%. This can save you time writing code when there's a lot of code written. And in addition to writing code, when you need to test it, it may or may not save time, unless you have a deep understanding of how to get your chosen library to do what you should do at test time, and using libraries may end up significantly longer than writing your own code.

The other thing you have to consider is how much code is included in a given library that will actually be used to achieve what you want to achieve, and whether the library actually includes all the actions you want. If you can't find a library with all the functionality you need, you'll need to write the rest of the code yourself or try to introduce a second library that includes the missing functionality. Depending on how the library works, you may or may not be able to use two libraries simultaneously in the same Web page.

In fact, the amount of JavaScript code you need to write yourself before you think about using the library will affect your decision. If you have written your own to perform all the different functions you need to handle, it is possible to eliminate the idea of using a library that also provides all of the same functions but different ways of implementing them. Given that these first people who write these libraries are generally people who have a deep understanding of JavaScript, one of the reasonable possibilities you have to admit is that a library that provides these functions is more efficient than what you write yourself (unless you also have a JavaScript expert).

The type of JavaScript processing you want to add to the Web page will also affect the appropriateness of using the library. If you only need a few lines of JavaScript code for a small effect to your Web page, using a library may cause you to write more code as an interface to how the library works, rather than writing all of your code. Of course, the reverse is also appropriate, if you want to add to your Web page is a large number of processing and the library you choose to closely match the type of functionality, then you can let the library for you to deal with.

Choosing a feature that closely matches the library you want to use into your Web page, and a good understanding of JavaScript and this library, can be quick and easy to add all the features you want, in a modern, unobtrusive way that might be the best way to do it. Plus, if you've been writing JavaScript for years and already have your code base that performs most of the functions you're constantly asking for, you can do quite a lot without having to choose and learn from any library.

Personal Summary

Personally, this article by Stephen Chapman a good contrast between the pros and cons of the JavaScript library and the code, in fact, if you can use the JavaScript library to make the best use of it to achieve its due value, That JavaScript library would be a great tool, a tool for creating rich clients and giving users a good experience, rather than being an extra burden when loading pages. For those who like to write code, I think it is also necessary to encapsulate some functions, such as DOM operations and event handling, after all, native JavaScript has more compatibility problems and efficiencies in different browsers (refer to the JavaScript layering concept of dawn). At the same time, I also think that if you use a popular JavaScript library (such as jquery, YUI, Ext JS), you can go to understand the implementation mechanism of these libraries, so as to better control these libraries!



Chinese by Vicky Translation, if reproduced please specify the source, translation if there are mistakes welcome message points out
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.