1) In the procedure is built-in object, 2) in the custom object
The code is described below
2.1.1 Define and create the object instance mode 1, the code is as follows:
<! DOCTYPE html>
<meta charset= "UTF-8" >
<title> Objects </title>
<body>
<script>
people= new Object ();
People.name= "Iwen";
People.age= "30";
document.write ("Name:" +people.name+ "; Age:" +people.age);
</script>
</body>
Operation Result:
2.1.2 Define and create the object instance mode 2, the code is as follows:
<! DOCTYPE html>
<meta charset= "UTF-8" >
<title> Objects </title>
<body>
<script>
People={name: "Lucy", Age: "32"};
document.write ("Name:" +people.name+ "; Age:" +people.age);
</script>
</body>
Operation Result:
2.2 Use a function to create an object, and then create a new object instance
The code is as follows:
<! DOCTYPE html>
<meta charset= "UTF-8" >
<title> Objects </title>
<body>
<script>
function people (Name,age) {
This._name=name;
This._age=age;
}
Son=new people ("Lilei", "10");
document.write ("Name:" +son._name+ "; Age:" +son._age);
</script>
</body>
Operation Result:
Mistakes that have been made:
son = new People ("Lily", 20);
son = people ("Lily", 20);
Day Fifth: Built-in objects (7. JavaScript built-in objects)