JavaScript Advanced Programming

Source: Internet
Author: User

The previous chapter briefly introduced the use of objects. Now we will introduce them in detail. Object creation or destruction occurs during JavaScript execution. Understanding the meaning of this paradigm is crucial to understanding the entire language. 3.2.1 declarations and instantiation objects are created with the keyword new followed by the name of the class to be instantiated: the first line of code creates an instance of the Object class and stores it in the variable oObject. The second line of code creates an instance of the String class and stores it in the variable oStringObject. If the constructor has no parameters, parentheses are not required. Therefore, you can rewrite the above two lines of code in the form below: 3.2.2 object reference introduces the concept of reference type in Chapter 2nd. In ECMAScript, you cannot access the physical representation of an object. You can only access the reference of an object. Each time an object is created, the objects stored in the variables are referenced by the object, rather than the object itself. 3.2.3 whether the ECMAScript object has a storage unit collection program is abolished means that the object is not destroyed to release the memory. When there is no reference to the object, the object is called dereference. When a useless storage unit collection program is run, all abolished objects are destroyed. Every time a function executes its code, useless storage units collect programs to run, release all local variables, and in some other unpredictable situations, useless storage unit collectors also run. To set all references of an object to null, the object can be forcibly abolished. For example, when the variable oObject is set to null, the reference to the first created object does not exist. This means that the object will be destroyed the next time you run the useless storage unit collection program. Every time an object is used up, it will be abolished to release the memory. This is a good habit. In this way, make sure that you no longer use inaccessible objects to prevent program design errors. In addition, the old browser (such as IE/Mac) does not have a comprehensive useless storage unit recycle program, so objects may not be correctly destroyed when the page is uninstalled. Abolishing an object and all its features is the best way to ensure proper memory usage. Be careful when abolishing all references to an object. If an object has two or more references, you must set all its referencesNull. 3.2.4 early binding and late binding the so-called binding, that is, the method of combining object interfaces with object instances. Early binding refers to defining the features and methods of an object before it is instantiated, so that the compiler or interpreter can convert the machine code in advance. In languages such as Java and Visual Basic, with early binding, you can use intelliisense in the development environment (that is, to provide developers with the features of the special object and method list ). ECMAScript is not a strong language, so it does not support early binding. On the other hand, late binding means that the compiler or interpreter does not know the object type before running. Late binding does not require you to check the object type. You only need to check whether the object supports features and methods. All variables in ECMAScript use the late binding method, which allows a large number of object operations without any penalty.

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.