In recent years, I have been focused on project management, and less on coding. These days are relatively free, I want to deposit the original experience, one is to do a good record, if forgotten later can be retrieved as soon as possible, the second is to write a blog, is to practice writing.

Anyway, this is Javascript class library. As you all know, Javacript is an interesting language. It’s a front-end language, but it can do a lot more than we thought. Javascript is also an object-oriented language, using it, you can also customize objects, also has some characteristics of objects, namely encapsulation, inheritance, polymorphism. At the same time, Javascript also has design patterns and can be used to write high-quality code, even if it is not necessary in many cases.

This time to write the Javascript class library, in fact, very simple, just use jQuery plug-in way to encapsulate a variety of custom functions, easy to call. Below is the Visual Studio 2013 solution diagram.

This is actually one of the architectures that defines Javascript, the way jQuery is architected-directory-based architecture. In the future, we will continue to supplement and improve the usage of the jQuery plug-in. In terms of architecture, I paid more attention to it in the past, but I want to play with it again recently, so I will have more about it in the future. NET architecture issues.

This time to write the class library is actually very simple, is encapsulated with jQuery, the use of Javascript anonymous functions. See my previous post on jQuery extensions and extension functions (a typical example of anonymous functions).

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

Those of you with a little Javascript background can understand this. It’s a simple static function based on anonymous jQuery functions.

Method of use: $. JSFn. FunctionWithOutParam ();

Then start looking at the code:

The extend method of jQuery is used here, which is a kind of encapsulation based on this way. The plugin is defined, that is, the function name is JSFn. Common is not used here, mainly because it is thought that this is some Javascript custom functions, which should be wrapped in the function library. The PlugInInfo static variable is also defined to declare some basic information about the class library.

Here’s an example of a library function:

First, declare the function name CheckBrowser, wrapped in the function anonymous function. Add a function declaration comment under the {sign of the function.

/// <summary> /// <returns> Returns the variable containing the browser information </returns> This must be added in this way, otherwise it will not get the smart function prompt when using the class library. See below.Copy the code

Let's look at the test case:Copy the code

This is simply to get the basic information about the static variables of the class library. The above test method can also be tested in the following way:Copy the code

Using the code above, you can insert this code anywhere on the page, after the element controls are loaded anyway. Finally, provide the function class library download, welcome to add and share out. http://files.cnblogs.com/lzhdim/JSFn.js briefly describes the Javascript function based on jQuery anonymous function library to write method, hope to be able to sort of help to you that is enough.Copy the code

Ps. Today is Thursday, time flies, and it will soon be the end of the year. Good luck writing good articles in the next few months.