What should I do when a newbie encounters problems using the JS library?

Source: Internet
Author: User

What should I do when a newbie encounters problems using the JS library?

See the title for details. During website creation, we will actually use a lot of JS libraries, popular on the Internet, and encapsulated by the company itself. These things are very useful, but there are more or less bugs or defects, even if they are perfect, they cannot meet their specific needs. Therefore, it is normal to encounter problems. But why is it a problem for a newbie? This is because, for some problems, it is easy to solve the siege Lions who have been working for several years. Therefore, they are not a problem at all, or they are private customization.

As a matter of fact, I have come over like this. If I want to completely encapsulate a very powerful JS library, I certainly cannot do it, not because of technology, but lack of experience, this is because many factors are required. Just like ORM, we will use very mature ones instead of encapsulating them ourselves.

Let's talk about how to solve the problems we encounter in the production environment? At that time, I would like to share with you the prerequisites, that is, access knowledge. Only in this way can we solve the problem.

I. access knowledge

A) JQuery & JS

This two basic must understand, specific can go to http://www.w3school.com.cn to learn

B) JS object-oriented

See: Senior Program Design in NLP, so this blog post is very good at object-oriented, some of which I have not noticed.

C) Implementation of JQuery & JS extension methods

As a matter of fact, we should all have encountered that JQuery and JS have no public methods to remove the front and back strings through front-end scripts, and I don't know why, in addition, all strings are replaced. By default, only the first matching string is replaced. There are also off-the-shelf blog posts for you to read.

JQuery: http://www.cnblogs.com/xcj26/p/3345556.html

JS: http://www.cnblogs.com/kissdodog/p/3386480.html

These two articles are both good, especially JQuery, which makes me understand something I didn't know before.

Below is a summary. Please prepare your knowledge in the order of a, B, and c. In fact, this is a technical sublimation. In fact, this is not difficult, we did not know it before. Therefore, it is necessary for us to grasp the knowledge to facilitate future work.

2. Read the code from others' JS Libraries

This is very important. You don't even understand other people's code. You can talk about how to modify or expand other people's code. At that time, I believe that as long as everyone reaches the entrance knowledge and reads some code that is not very complex, I believe there is not much problem with me. Therefore, it is critical to grasp the foundation, and it cannot be a bit false.

We need to be bold and meticulous in reading other people's code. Everyone is writing programs, and the JS library is also written by people. Others are better than us, but we still need to implement them by JS syntax, it's just higher than our writing level. Just as we couldn't get the full score for the college entrance examination, but we wouldn't even understand the full score. In this case, I am in a hurry for you.

3. Try to modify the code in the JS Library

This is the end, but I want to emphasize that it is not easy to modify the popular code on the network. How can I modify the code, but why not modify it easily? Don't be confused. Don't let the modifications take into account that these JS libraries are maintained by a very professional team and the code is highly rigorous. If you change the code, it is likely to affect the use of the entire JS library. Even if it is a Bug or requires customized features, we recommend that you implement and extend it again. In this way, the JS library upgrade and self-implemented code can be independent. If you have modified the JS library code, remember to record the document. If you have upgraded the JS library, your modified code will be overwritten, your work is in vain. It is a common practice that allows you to modify the library code.

Here is an example of my work.

There is a locally saved prompt message on the right. Many people want to remove this information. The closing parameter is also provided officially, but it cannot achieve the effect we don't expect, however, designing the Automatic Storage interval for a long time seems to achieve the expected results, but this method is indeed not reasonable.

First, we need to find the source of this prompt.

We can see that this is actually a configuration file. We can guess how to use it. First, we can see that the key name corresponding to this value is success, it is hard to find, but we can see the node name autosave. We don't even want to think about it. This node will definitely appear in the code. Let's search for the two images.

This is the two pieces of code that most likely result in a prompt message. Let's take a closer look at these two sections of code to see what they are.

Here is a blog post: http://www.kissthink.com/archive/--4232.html

Here we can know that the second image is actually to allow automatic storage, so we put it in the first image.

We have found this keyword and have no impression. Where have we met this keyword? For this keyword, it is in the configuration file. At the beginning, we said that setting the interval takes effect, setting enable auto save does not work, so the keyword enableAutoSave we searched is not found in the entire library. This indicates that this function is not implemented at all.

We can use the upper level to generate this in the code. The result is as follows:

In summary, this is only for the purpose of implementing the effect. I did not go into details about the code from other places, but I think this modification should not affect other places. I don't think it is possible to modify others' code. The difficulty is that the modification will not lead to new problematic parameters. Again, do not modify the code as easily as I do. If you can find out the implementation method outside the code is the best.

Copyright:

This document consistsZ-albertThis article is original and published in the blog Park. You are welcome to repost it. You cannot modify the original content without your consent and must retain this statement, and provide the original article link clearly on the article page, otherwise, you are entitled to pursue legal liability. If you have any questions, welcome to leave a message, you can also contact me through y442926727@qq.com, thank you very much.

Due to my limited technical skills and text expression skills, please criticize and correct me if any descriptions are incorrect or unclear! If you are interested, add a group: 144063225 for communication.

For more information, please refer to blog: http://www.cnblogs.com/z-albert/

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.