Java application-write Advanced JavaScript code

Source: Internet
Author: User

A constructor is a function that calls it to demonstrate and initialize special types of objects. You can use the new keyword to call a constructor. The following is a new example of using constructors.
[Keyword] javascript constructor Java 1. Create an advanced object

Use constructors to create objects

A constructor is a function that calls it to demonstrate and initialize special types of objects. You can use the new keyword to call a constructor. The following is a new example of using constructors.

Var myObject = new Object (); // create a common Object without attributes.

Var myBirthday = new Date (1961, 5, 10); // create a Date object.

Var myCar = new Car (); // create a user-defined object and initialize its attributes.

The constructor transmits a parameter as the value of the specific this keyword to the newly created null object. Then, the constructor is responsible for initializing the new object (creating attributes and providing their initial values ). After completion, the constructor returns a parameter of the object it constructs.

Compile Constructor

You can use the new operator to create and initialize an Object with predefined constructors such as Object (), Date (), and Function. Object-Oriented Programming its powerful feature is the ability to define custom constructor to create custom objects used in scripts. A user-defined constructor is created to create objects with defined attributes. The following is an example of a user-defined function (note the use of this keyword ).

Function Circle (xPoint, yPoint, radius ){

This. x = xPoint; // The x coordinate of the center.

This. y = yPoint; // y coordinate of the center

  • 5 pages in total:
  • Previous Page
  • 1
  • 2
  • 3
  • 4
  • 5
  • Next Page

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.