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.