JS uses object direct quantity to create object's code _javascript skill

Source: Internet
Author: User
Object Direct volume provides another way to create new objects. Object immediacy allows you to embed object description text into JavaScript code, just as you embed text data in JavaScript code, just as you would embed text data in JavaScript code as a reference string. The object's direct volume is composed of a list of attribute descriptions, which are enclosed in curly braces, where the property descriptions are separated by commas. Each property description list in the object's direct volume consists of a property name followed by a colon and a property value. The general format for creating objects using object Direct volume is as follows:
var MyObject = {Property Name 1: Property value 1, Property 2: Property value,..., Property name N: Property value N}
As you can see from this definition, this definition is actually declaring a variable of a type and assigning it at the same time. As a result, the declared object direct amount can be used directly in your code without having to use 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> </body> </ptml> <script language= "javascript" type= "Text/javascript" > var circle = {x: 0,y:0,radius:2} document.write (circle.x + "" + Circle.y + "" + Circle.radius); </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

This method simply creates an instance of the object, and if you want to create multiple instances of the object, you need to write the object directly.

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.