コードコピーは次のとおりです。
<!doctype html>
<html>
<head>
<メタcharset = "utf-8">
<Title>タイトルを挿入して</title>
<script type = "text/javascript">
/*
*コンビネーションモード:コンストラクターモード +プロトタイプモード
この方法は、JavaScriptでオブジェクトを作成する最も一般的な方法です
可変型属性:コンストラクターで渡されます
関数型属性:プロトタイプモードで宣言されています
*/
関数学生(名前、年齢){
this.name = name;
this.age = age;
}
Student.prototype.setname = function(name2){
this.name = name2;
};
desuten.prototype.getName = function(){
this.nameを返します。
};
var stu1 = new Student( "Xiao Hu"、21);
alert(stu1.getname());
</script>
</head>
<body>
</body>
</html>