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.