- 1
- 0
- 约1.93千字
- 约 3页
- 2018-03-29 发布于河南
- 举报
(一)Javascript经验总结面向对象:类
随着不断的学习,越来越觉得大脑容量不够,装不下那么多的东西,话说好记性不如烂笔头,应当写些东西,以??? 便日后查阅之用,在此将把javascript的学习笔记写下。
??? javascript中的类是用函数表示的,如下:
??? function Student()
??? {
??????? this.studentNo = s001;??? //定义类Student中的字段,并赋予初值,但此字段的访问权限是public
??????? this.studentName = 小明;
??????? this.sex = 男;
??????? //定义类Student中的方法updateStudentName ,用于修改studentName 值
??????? this.updateStudentName = function(studentName)?
? ? ?? {
?????? ? ?? this.studentName? = studentName;
?????? }
??? }
??? 如上代码便已定义了一个Student类,并包含studentNo ,studentName ,sex? 3个字段,方法updateStudentName.
??? 下面将进行调用,代码如下:
??? var s = new Student();? //创建student类的对象
原创力文档

文档评论(0)