Js uses objects to directly create object code

Source: Internet
Author: User

The object quantity provides another way to create a new object. The object quantity allows you to embed the object description text into JavaScript code, just like embedding text data in JavaScript code, just like embedding text data in JavaScript code as referenced strings. The object direct quantity is composed of the attribute description list, which is included in braces. The attribute description is separated by commas. Each attribute description list in the object's direct quantity consists of an attribute name and the colon and attribute value following it. The general format for directly creating objects using objects is as follows:
Var myobject = {attribute name 1: attribute value 1, attribute 2: attribute value,..., attribute name n: attribute value n}
From this definition, we can see that this definition method is actually to declare a type of variable and assign values at the same time. Therefore, the declared object quantity can be directly used in the code without using the new keyword to create the object.
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ptml xmlns = "http://www.w3.org/1999/xhtml"> <pead> <title> untitled page </title> </pead> <body> </ptml>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
This method only creates an instance of this object. If you want to create multiple instances of this object, you need to write the object multiple times.

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.