(The following questions are only for JavaScript. Please note that if there is a problem with the explanation, please just laugh it off)
1. What is a static class/pseudo-static class
2. The syntax for writing static classes in javsscript is How is it? (Including arrays, constants, etc., must be complete)
3. Give a simple example for your explanation
The key is the second one, you don’t need to mention the others
Static classes are top-level classes For example, Math The transparent point of class is actually the global variable, but this variable is not defined by you but JS itself. You can just use it. It is better to use the Math class without creating an object at all. If you want to find the area of a circle Just do this: s=Math.PI*r*r. The variable r must be declared first.
There are also static methods, which are all the same. For example, if you want to create a string, you can use the static method of the string class fromCharCode(value1, value2, value3....) Just like this
str=String.fromCharCode(value1,value2,value3....)
]
First of all, thank you to the lovely WT1985 and dear hutia:D, thank you With the help of
I have figured out the essence of this thing. I have also figured out most of the things from hutia’s example. Let me explain my understanding first:
1. This thing is straightforward. It is (global variable/constructor that can be used without instantiation)
2. This thing can play a role similar to the "class" in other languages
3. The syntax of this thing is roughly the same as usual writing. But it has to be changed to
(attribute name/method name): (attribute value/method description)
4. Separate each attribute with ","
Then
function funcname(ipt1 ) written as funcname function(ipt1)
var str="value" written as str:"value"
var myarray=new Array() written as myarray:[] (this is a guess based on my example from Foshan)
What about the grammar rules for other objects? The first two can be roughly guessed, but if you don't look at the example of me from Foshan, you won't know the "[]" symbol for declaring an array. Is there a specific rule? Can any big brother or sister explain it again: confused:
You summed it up very well, there is nothing wrong with it
As for your last question, it is actually just the syntax of JS
a=new Array(); a[0]=1; a[1]=2;
is equivalent to
a=[1,2];
and similar With
a=new Object(); a.name="hutia";
is equivalent to
a={ name:"hutia" }
In general , JS still has a lot of unfamiliar syntax, let’s take another example:
If you need to introduce external Js, you need to refresh to execute <script>
var Hutia_Hate_StaticClass={
name:"hutia", // A property
sex:"unknown", // Another property, be aware that you should 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>]<script>
(function(name){window["eval"]("alert('I am "+name+"')");})("hutia")
</script>