Encapsulate your own JavaScript class library (i)

Source: Internet
Author: User

I. Background of motivation

Why do you suddenly want to write your own JavaScript library as a. NET backend developer for more than five years?

The first is to improve their front-end level (stimulated), followed by the project requirements, again in order to understand some of the front-end of the wording and.

Stimulation from last 2-April in a company to do a project, the project is divided into three subsystems: PC-side web site, PC-side backend management platform, end (said there are apps). The business is questionnaire design, questionnaire survey and statistical analysis. I went directly into the development phase, and the developer, plus a front-end development (only static pages, not responsible for invoking the data and the front-end framework), the company does not have any platform framework code accumulation. (now think of this project is really a very fucked, deep pit ah) and then I took the front-end write those static pages for database design, front-end integration development, end development. Like this questionnaire design interface because the front-end of the freedom is too large, involving a lot of dynamic DOM elements and DOM operations, so the front-end workload is quite large, plus my home company is to use their own platform for development, so I also learn while developing, Can imagine the front-end written like excrement (one is not spent time to think and study the front end, two years ago, the accumulation of knowledge is not enough, the third is just their knowledge accumulation can solve the problems encountered at the front end, just write to compare the ugly).

Until a while ago, I in the current B company again encountered H5 project (server side is Nodejs, backend is Java WebService), one months the entire project development completed (business is relatively simple). Find yourself writing a lot of duplicate code in the H5 page, one is this very ugly, and the other is the project file too much slow loading (mobile must consider the loading speed), plus the time is more abundant, so you want to encapsulate the front-end code.

I found the project that I did last year, researched the front-end code, found that the entire project front-end code was encapsulated, a look at a front-end Daniel was reconstructed (which caused me a certain shock and stimulation), I was determined to learn to write a front-end class library.

The background is complete, the following will enter the topic: How I learn while writing their own front-end class library.

Ii. preparatory work

In the study of other people's front-end library process, some of the way I look at the face of a crazy, such as:

  

After reviewing the study, we learned that there are several JavaScript concepts used here: Anonymous functions, immediate execution functions, immediate execution of anonymous functions, scopes, scope chains, and closures.

anonymous function: A function without a function name.

Execute function immediately: the function that executes immediately.

Perform an anonymous function immediately: a function that executes immediately without a function name.

Scope: The scope in which variables and functions are accessible, that is, scope controls the visibility and life cycle of variables and functions.

Iii. Building a class library

Analysis and integration of each JS file repeat code, analysis system and page loading sequence and logic.

  

Encapsulate your own JavaScript class library (i)

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.