Writing JavaScript Class library (jquery Edition)-Advanced series-Learner series articles

Source: Internet
Author: User

These years have focused on project management, with fewer codes. These days more idle, want to the original experience precipitation down, one is to do a good record, later if you forget to get back as soon as possible, the second is to write a blog, is to practice writing it.

In this case, the JavaScript class library was written. As we all know, Javacript is a very interesting language. Although it is the front-end language, it can do things far beyond our imagination. JavaScript is also an object-oriented language, using it, you can also customize the object, also has some of the characteristics of the object, that is, encapsulation, inheritance, polymorphism. At the same time, JavaScript also has a design pattern, also can write high-quality code, although in many cases it is not necessary.

This time to write the JavaScript library, in fact, is very simple, just use the jquery plug-in way to encapsulate a variety of custom functions, easy to call. The following is a solution diagram for Visual Studio 2013.

This is also a schema that defines JavaScript, the way jquery is architected (directory-based architecture). Follow-up will continue to complement and refine the use of the jquery plugin and so on. About the architecture, the previous concern is relatively more, but recently want to turn out to play, so the follow-up will be about. NET architectural aspects of this issue.

The class library written this time is actually very simple, is to use jquery encapsulation, using JavaScript anonymous function. See my previous blog post: How jquery extensions and extension functions are written (typical examples of anonymous function use).

The following is a brief description of the class library. First look at the writing method description:

People who believe that there is a bit of JavaScript foundation can understand. The use of the method is simple, is based on the anonymous function of jquery writing static function.

How to use: $. Jsfn.functionwithoutparam ();

Then start looking at the code:

Here is an extension of the jquery extend method, which is a package based on this approach. Defines the plug-in, that is, the function name is JSFN, there is no use of common, mainly think that this is a javascript of some of the custom functions, should be encapsulated in the function library. It also defines the static variable plugininfo, which declares some basic information about the class library using static variables.

Below is a description of the functions in a library:

First, declare the function name Checkbrowser, encapsulating it with function anonymous functions. Add a function declaration comment below the {number of the function.

<summary>

Detecting browsing Information

</summary>

<returns> returns variables that contain browser information </returns>

You must add comments like this , or you will not be able to get smart function hints when using this class library. See.

Here's a look at the test case:

This is simply the basic information for some static variables of the class library.

The above test methods can also be tested in the following ways:

Using the code above, you can insert the code anywhere on the page, and then execute it after the page element control is loaded.

Finally, we provide the download of the Function class library, welcome to add and share it.

Http://files.cnblogs.com/lzhdim/JSFn.js

The above briefly describes the writing method of JavaScript function class library based on jquery anonymous function, I hope to have a little help to everyone that is enough.

Ps. Today is Thursday, the time is fast, and it is coming to the end of the year. May there be good articles written in the remaining months.

Writing JavaScript Class library (jquery Edition)-Advanced series-Learner series articles

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.