<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
/*
* 组合模式: 构造函数模式+原型模式
这种方式是javascript中最通用的创建对象的方式
变量类型属性:用构造函数传递
函数类型属性:用原型模式声明
*/
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>
构造函数+原型模式构造js自定义对象
原创mb60b8936aed2b7 ©著作权
文章标签 JS开发 JS教程 前端开发 文章分类 JavaScript 前端开发
-
js17---创建对象:构造函数式和原型组合模式、动态原型模式、稳妥构造函数式
Untitled Document
html 构造函数 封装 原型对象 原型模式