Copy codeThe Code is as follows:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Title> Insert title here </title>
<Script type = "text/javascript">
/*
* Use. To add attributes to an object
Delete attributes with the keyword "delete"
Use [] to add attributes
Different from.
R. name = r ["name"];
R. name can only add string attributes
[] Adding a property. It is powerful and can be dynamically added.
*/
Var r = new Object ();
Alert (typeof (r ));
// Add attributes
R. name = "jobs ";
Alert (r. name );
R. getname = function (){
Return "jobs ";
}
Alert (r. getname ());
// Delete attributes
Delete r. name;
Alert (r. name); // The result is undefined.
//--------------------------------------------
// Use brackets to add attributes for objects
R ["name"] = "tom ";
Alert (r ["name"]);
R. name = "toms ";
Alert (r ["names"]);
// R. name = r ["name"] // the two statements are equivalent.
Var arg = "abc ";
R [arg] = "heima"; // powerful function. You can dynamically add attributes to make a string returned by a function variable
R. arg = "itcast"; // arg is a string by default.
</Script>
</Head>
<Body>
</Body>
</Html>