当前位置:网站首页>1-4 类的复习
1-4 类的复习
2022-07-28 22:08:00 【画不完的饼】
类的复习
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>类</title>
</head>
<body>
<script type="text/javascript">
/*
总结:
1.类中的构造器不是必须写的,要对实例进行一些初始化的操作,如添加指定属性时才写。
2.如果A类继承了B类,且A类中写了构造器,那么A类构造器中的super是必须要调用的。
3.类中所定义的方法,都是放在了类的原型对象上,供类的实例对象调用。
*/
//创建一个类
class Person{
//构造器方法
constructor(name,age){
this.name = name
this.age = age
}
//一般方法
//speak方法放在了类的原型对象上,供实例使用
//通过Person实例调用speak时,speak中的this就是Person实例
speak(){
console.log(`我叫${this.name},年龄${this.age}岁`)
}
}
//创建一个 student类
class Student extends Person{
constructor(name,age,grade){
super(name,age)
this.grade = grade
}
speak(){
console.log(`我叫${this.name},年龄${this.age}岁,我读的是${this.grade}年级`)
}
study(){
console.log('我很努力的学习')
}
}
const s1 = new Student('xiaozhg',15,'高一')
s1.speak()
s1.study()
</script>
</body>
</html>
边栏推荐
- pycharm新建项目
- 双重for循环优化
- 数仓:Doris在美团的应用实践
- DevOps在物联网解决方案中的应用
- VS2005透过SourceOffSite访问VSS2005的设置方法「建议收藏」
- 【C】atoi和offsetof的介绍和模拟实现
- 【CNN】为什么CNN的卷积核大小一般都是奇数
- Hutool official website (is hutool easy to use)
- Worthington核糖核酸测定详细攻略
- A new generation of ultra safe cellular battery, Sihao aipao, will be available from 139900 yuan
猜你喜欢

Multi sensor fusion positioning (II) -- map based positioning

Equipped with a new generation of ultra safe cellular batteries, Sihao aipao is available from 139900 yuan

电脑不知卸载什么,打不开计算器无法编辑截图功能打不开txt文件等等解决方案之一

YOLOV5学习笔记(一)——原理概述

Eight performance analysis indicators of effective supply chain management (Part 1)

Deep analysis of integrated learning AdaBoost

Machine learning problem notes

控件 圆角描边 MaterialShapeDrawable

AUTOCAD——Excel表格导入CAD、CAD合并两兄弟

RHCE first day
随机推荐
Zero view h5s video platform getUserInfo information disclosure vulnerability cnvd-2020-67113
DevOps在物联网解决方案中的应用
Best practices for migration of kingbasees v8.3 to v8.6 of Jincang database (2. Compatibility of kingbasees v8.3 and v8.6)
Eight performance analysis indicators of effective supply chain management (Part 1)
xss.haozi.me靶场详解
Deep analysis of integrated learning xgboost
pycharm新建项目
A new generation of ultra safe cellular battery, Sihao aipao, will be available from 139900 yuan
经典双栈实现队列,注意遍历栈的判定条件修改。
请简述list,set,map类型的集合的各自特点(简述三种不同的继承方式下)
你学过的每样东西,都会在你一生中的某个时刻派上用场(转)
Explanation of history and chemical properties of Worthington ribonuclease B
【CNN】为什么CNN的卷积核大小一般都是奇数
猿人学第二十题
field injection is not recommended 的解决办法
解决:Direct local .aar file dependencies are not supported when building an AAR.
sql 左连接,内连接 的写法「建议收藏」
Xss.haozi.me range details
实时数仓:美团基于Flink的实时数仓建设实施
Deep analysis of integrated learning AdaBoost