Here we will introduce the JavaScript static class and JSON. Many people doubt the relationship between JavaScript static and JSON. I believe you will have your own opinions after reading the full text.
Let's first look at a simple static class. There is no method for only public fields.
Var Person = {id: 1, name: "Jerry "};
I don't know whether you have found it is similar to the JSON format.
Var Person = {"id": 1, "name": "Jerry "};
We should have discovered the difference between a JSON object and a static class. The key name of a static class is a string with double quotation marks, while that of a static class is not a public field or method, however, there is no difference in usage. I don't understand why the JSON standard is like this, the following figure comes from the http://www.json.org/
I personally prefer the first format. Next I will introduce the static class as a verification tool class.
First, a regular enumeration is required.
- // Regular expression-it can be regarded as a static class or an enumeration class.
- Var Regex = {
- Number:/^ \ d +/
- };
The following is the verification tool class. Of course it is not very powerful. I am just a small example here to illustrate the usage of JavaScript static classes.
- // Verification tool-static class
- Var Validate = {
- // Icon-public field, I do not know how to implement private field
- IconOk:"OK",
- IconError:"Error",
- // Static method-Enumeration
- Match: function (regex, text ){
- // This keyword is required for internal use of fields.
- If(Regex. test (text ))
- Document. getElementById ("Error"). InnerHTML =This. IconOk;
- Else
- Document. getElementById ("Error"). InnerHTML =This. IconError;
- }
- };
-
- "Text" Onblur = "Validate. match (Regex. number, this. value )" />
- "Error">
- Conversion from JavaBean to XML and JSON
- Detailed introduction to JSON-based advanced AJAX Development Technology
- Detailed description of the Java Bean application steps for JSP instances
- Call JavaBean in JSP
- JSP Servlet JavaBean built under jdk6.0 Tomcat6.0