Copy Code code as follows:
<! DOCTYPE html>
<meta charset= "UTF-8" >
<title>insert title here</title>
<script type= "Text/javascript" >
/*
* use. To add properties to an object
Delete an attribute with the keyword delete
Add attributes with []
The difference between the and.
r.name==r["Name"];
R.name can only add string properties
[] Add properties, powerful, can add properties dynamically
*/
var r=new Object ();
Alert (typeof (R));
Add properties
R.name= "Jobs";
alert (r.name);
R.getname=function () {
return "Jobs";
}
Alert (R.getname ());
Delete attribute
Delete R.name;
Alert (R.name)//The result of this is undefined.
//--------------------------------------------
To add a property to an object by using the brackets
r["Name"]= "Tom";
Alert (r["name"]);
R.name= "Toms";
Alert (r["names"]);
r.name==r["Name"]//these two ways are equivalent.
var arg= "abc";
R[arg]= "Heima";//powerful, can dynamically add properties, you can make a function variable returned a string
R.arg= "Itcast";//arg default to String
</script>
<body>
</body>