手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >构造函数+原型模式构造js自定义对象(最通用)
构造函数+原型模式构造js自定义对象(最通用)
摘要:复制代码代码如下:Inserttitlehere/**组合模式:构造函数模式+原型模式这种方式是javascript中最通用的创建对象的方式...

复制代码 代码如下:

<!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自定义对象(最通用)】相关文章:

document对象execCommand的command参数介绍

详解AngularJS中的表格使用

js输入中文效果

jQuery构造函数init参数分析续

JavaScript中search()方法的使用

优化RequireJS项目的相关技巧总结

JS、HTML代码运行工具

AngularJS中的一些常用指令介绍

免费空间广告万能消除代码

无刷新上传文件并返回自定义值

精品推荐
分类导航