JavaScript Object definition and instance creation (1)

Source: Internet
Author: User

Here we will describe how to create a new object in JavaScript. It is very easy to create a new JavaScript Object in JavaScript. Although the functions inside JavaScript and the browser itself are very powerful, JavaScript still provides a method to create a new JavaScript Object.

Create an object in JavaScript

You can use JavaScript to create your own objects. Although the functions inside JavaScript and the browser itself are very powerful, JavaScript still provides a method to create a new JavaScript Object. So that it does not have to perform a lot of complex work as the hypertext mark language requires or other multimedia tools.

It is very easy to create a new JavaScript Object in JavaScript. First, it must define a JavaScript Object and then create an instance for the JavaScript Object. This example is a new JavaScript Object with basic features in the JavaScript Object definition.

I. JavaScript Object Definition

The basic format of JavaScriptJavaScript object is as follows:

 
 
  1. FunctionObject Attribute Table)
  2.  
  3. This. prop1 = prop1
  4.  
  5. This. prop2 = prop2
  6.  
  7. ...
  8.  
  9. This. meth = FunctionName1;
  10.  
  11. This. meth = FunctionName2;
  12.  
  13. ...

In the definition of a JavaScript Object, you can specify its attributes and methods for this JavaScript Object. A JavaScript object instance is composed of attributes and methods. The following is a definition of the UniversityJavaScript object:

 
 
  1. Functionuniversity(name,city,creatDateURL)  
  2.  
  3. This.name=name  
  4.  
  5. This.city=city  
  6.  
  7. This.creatDate=NewDate(creatDate)  
  8.  
  9. This.URL=URL  
  10.  

Its basic meaning is as follows:

Name-specify a "unit" Name.

City-the City in which the Unit is located.

CreatDate-specifies the update date of the universityJavaScript object.

URL-This JavaScript Object points to a URL.


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.