Syntax format and usage of the with () method in javascript, javascriptwith
With the With statement, you do not need to specify the reference object when accessing the object attributes and methods. In the With statement block, any properties and methods that JavaScript does not recognize are related to the objects specified by the statement block. The syntax format of the With statement is as follows:
The With Object {Statements} Object specifies a reference Object that is time-saving when the objects in the statement group are missing. Here we use a familiar Document Object to give an example of the With statement. For example, when using the write () or writeln () method related to the Document object, the following format is often used: document. writeln ("Hello! ") If you need to display a large amount of data, the same document will be used multiple times. writeln () statement. In this case, all the statements With Document objects as reference objects can be placed in the With statement block as the program below to reduce the number of statements. The following is an example of the With statement:
In this way, you can remove the document prefix when using the Document method and attributes.
A syntax problem in javascript (for methods)
The first floor provides a good explanation, but he may not understand it for beginners.
The so-called method refers to the method of the object. That is, the method is a term for object-oriented programming, while the function is process-oriented. Therefore, methods are attached to objects. The toString () method is not a method, but many methods. For example, in Object-Oriented Programming:
Datetime. protopty. toString ()
The definition of such a method is to define a method for the datetime prototype. That is to say, this method can be used for the date and time type, but if every prototype has such a method. Each type of object can be used. That is to say, toString does not only have this method for data objects, but also for others. Different toString () methods are called based on different objects. Because each method has the same function, so many people think that toString is one, but it is not. If we understand it by prototype, it should be that a prototype has a toString () method, except the string prototype. Of course, this method does not require parameters, so the content in the brackets is empty.
The parseInt method is an Integer object of the prototype. It does not have any other prototype. It can be used in two ways. You can add data between 1 and 36 to indicate the hexadecimal format. For example, parseInt (string, 16) indicates converting to hexadecimal. Haha. However, this concept is prototype, so we do not need to point out the prototype, that is, integet. parseInt (string) can omit the prototype, as long as it is a prototype.
You may not understand why toString () cannot be omitted, but writing toString () directly. This is when more than two prototypes have written such a method, if you omit it, you do not know which one to execute, so the prototype must be included. This indicates the prototype of the object to be executed.
In the weak-definition javascript code, its connections can be automatically converted. Of course, this is a specific definition process, but all of them are switched to the fully-defined javascript code, except for the specific ones. Therefore, for any type, you can use the + "" method to convert it into a string. This is the benefit of toString in each type. It is implemented internally and cannot be seen.
Syntax problems in javascript js files
1 This is an anonymous function (function a () {alert (1)};) (); you can try to execute
2 prototype is a prototype object. Every Function has this object. Every new object has an internal pointer pointing to this prototype object.
Function (){
This. name = 'taobao ';
}
A. prototype. getName = function () {alert (this. name );};
Var obj = new;
Var obj2 = new B;
Obj. getName ();
You can run the getName functions of obj1 and obj2 in this way to point to a function. This is the real meaning of the prototype.
3
The colon operator does not exist in normal javascript.