コードコピーは次のとおりです。
<!doctype html>
<html>
<head>
<メタcharset = "utf-8">
<Title>タイトルを挿入して</title>
<script type = "text/javascript">
/**
* JSONオブジェクトの形式
{key:value、key:value、key:value ..}
*/
//オブジェクトを作成する小さな例
// ------ 1
var r = {};
R.Name = "Tom";
r.age = 18;
// ------ 2
var r = {name: "tom"、age:20}; // jsonオブジェクト
アラート(r.age);
// --- 1,2は同等です
// ------------プロトタイプモードの書き込み
// ---- 1
function person(){};
person.prototype.name = "中国語";
person.prototype.age = 20;
//プロトタイプモードの略語-2
function person(){};
person.prototype = {name: "中国語"、
年齢:20、}
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------ -
// ============================================================================== ==============================================================================
/* {名前:「中国語」、
年齢:20、}
上記の形式自体はオブジェクトです。別のオブジェクトのプロトタイプに支払うと、
別のオブジェクトのすべてのプロパティ。本質的に、それは継承です
*/
// ============================================================================== ==============================================================================
//標準オブジェクトの継承例、人、学生
//個人のオブジェクトを定義します
function person(){};
person.prototype.name = "中国語";
person.prototype.age = 20;
var person = new Person();
//学生オブジェクトを定義します
function student(){};
Student.prototype = person;
Student.prototype.girlfriend = "can beavail";
var stu = new Student();
stu.laop = "愛は許されません";
Alert(Stu.Name); //親オブジェクトから継承されたインスタンス
アラート(stu.laop); //新しい属性が自分で追加されました
//チームリーダーオブジェクトを定義します
function teamleader(){};
TeamLeader.prototype = new Student(); //学生から継承されます
TeamLeader.Prototype.TeamNum = 8; // TeamLeader自身のプロパティ
//独自のインスタンスを作成します
var teamLeader = new TeamLeader();
Alert(TeamLeader.TeamNum);
teamleader.girlfriend = "not not abailing";
Alert(TeamLeader.Name);
// ============================================================================== ==============================================================================
/*JSの継承の中核はプロトタイプです*/
// ============================================================================== ==============================================================================
</script>
</head>
<body>
</body>
</html>