復(fù)制代碼 代碼如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
/*
* 組合模式: 構(gòu)造函數(shù)模式+原型模式
這種方式是javascript中最通用的創(chuàng)建對象的方式
變量類型屬性:用構(gòu)造函數(shù)傳遞
函數(shù)類型屬性:用原型模式聲明
*/
function Student(name,age){
this.name=name;
this.age=age;
}
Student.prototype.setName=function(name2){
this.name=name2;
};
Student.prototype.getName=function(){
return this.name;
};
var stu1=new Student("小胡",21);
alert(stu1.getName());
</script>
</head>
<body>
</body>
</html>
新聞熱點(diǎn)
疑難解答
圖片精選