"Static class" _ javascript skills about javascript

Source: Internet
Author: User
About javascript's "static Class & quot; (the following questions are only raised for javascript. Please note that if you have any questions, just laugh)
1. What is static or pseudo-static?
2. What is the syntax for writing static classes in javsscript? (Including arrays, constants, and so on)
3. Give a simple example.
The key is the second article. You can leave it alone.
Static classes are top-level classes, such as Math class. The transparency point is actually a global variable, however, this variable is not defined by you, but is defined by JS itself. You just need to use it. Instead, you do not need to create a photo object using the Math class. If you want to obtain an area of a circle, you only need to do this. s = Math. PI * r variable r must be stated first
There are also static methods and so on. For example, to create a string, use the static method fromCharCode (value1, value2, value3. ......) of the string class.
Str = String. fromCharCode (value1, value2, value3 .....)

Script var Hutia_Hate_StaticClass = {name: "hutia", // A property sex: "unknown", // Another property, be aware that you shoshould use, to devide two variable talk: function (words) {// The method for the object alert (words) ;}} Hutia_Hate_StaticClass.talk ("I am" + Hutia_Hate_StaticClass.name); script
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]


First of all, thank you for the lovely WT1985 and dear hutia: D. Thank you for your help.

I have understood the essence of this thing, and I have understood most of the things from the examples of hutia. Let me first explain my understanding:
1. This is something like (global variable/constructor that can be used without instantiation)
2. This is something similar to the "class" in other languages.
3. the syntax of this item is basically the same as that in normal times, but it must be changed
(Attribute/method name): (attribute value/method description)
4. Each attribute is separated by commas (,).

So
Function funcname (ipt1) is written as funcname function (ipt1)
Var str = "value" written as str: "value"
Var myarray = new Array () is written as myarray: [] (this is an example of my Buddhist examples)

What about the syntax rules of other objects? The first two can still be guessed, but if the "[]" symbol of the declared array does not look at my Buddha's example, I don't know at all. Is there a specific rule? Which Big Brother and big sister will explain: confused:
You are right. No problem.

Your last question is actually just the JS syntax.

A = new Array (); a [0] = 1; a [1] = 2;
It is equivalent
A = [1, 2];

Similarly
A = new Object (); a. name = "hutia ";
It is equivalent
A = {name: "hutia "}


In general, JS still has a lot of uncommon syntaxes. Let's take another example.

Funny Syntax: script (function (name) {window ["eval"] ("alert ('I am" + name + "')");}) ("hutia") script
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

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.