The code copy is as follows:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
/**
* format of json object
{key:value,key:value,key:value..}
*/
//Small example of creating an object
//------1
var r={};
r.name="tom";
r.age=18;
//------2
var r={name:"tom",age:20};//json object
alert(r.age);
//---1,2 are equivalent
//------------Writing of prototype mode
//----1
function Person(){};
Person.prototype.name="Chinese";
Person.prototype.age=20;
//The abbreviation of prototype mode--2
function Person(){};
Person.prototype={name:"Chinese",
age:20,}
//-----------------------------------------------------------------------------------------------------------------------------
//=============================================================================================================================
/* {name:"Chinese",
age:20,}
The above format is itself an object. If you pay it to another object's prototype, it will make
All properties of another object. In essence, it is inheritance
*/
//=============================================================================================================================
//Standard object inheritance examples, Person, Student
//Define a Person object
function Person(){};
Person.prototype.name="Chinese";
Person.prototype.age=20;
var person=new Person();
//Define a Student object
function Student(){};
Student.prototype=person;
Student.prototype.girlFriend="can be available";
var stu=new Student();
stu.laop="No love is allowed";
alert(stu.name);//Instance inherited from the parent object
alert(stu.laop);//New attribute added by yourself
//Define a Teamleader object
function Teamleader(){};
Teamleader.prototype=new Student();//Inherited from Student
Teamleader.prototype.teamNum=8;//Teamleader's own properties
//Create your own instance
var teamleader=new Teamleader();
alert(teamleader.teamNum);
teamleader.girlFriend="Not available either";
alert(teamleader.name);
//=============================================================================================================================
/*The core of inheritance in js is prototype*/
//=============================================================================================================================
</script>
</head>
<body>
</body>
</html>