当前位置:网站首页>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>
边栏推荐
猜你喜欢
Leetcode63. 不同路径 II
Codeforces Round #810 (Div. 2) A - C
RHCE first day
Is the declarative code of compose so concise?
Solve thread safety problems & singleton mode
【C】逆序字符串(俩种递归思路)
Wildcard ssl/tls certificate
2022 R2 mobile pressure vessel filling test question simulation test platform operation
使用Pytorch快速训练网络模型
器利而工善,以RPA+LCAP赋能企业司库管理数字化升级
随机推荐
Solve thread safety problems & singleton mode
Briefly introduce the working principle and characteristics of block cipher encryption block link mode (cryptography shift cipher encryption and decryption)
Leetcode64. 最小路径和
xss.haozi.me靶场详解
Worthington核糖核酸酶B历史和化学性质说明
2022 G2 power plant boiler stoker examination question bank simulated examination platform operation
SAP oracle 复制新实例后数据库远程连接报错 ora-01031
Exchange 2013 SSL证书安装文档
编译原理研究性学习专题 2——递归下降语法分析设计原理与实现
Best practices for migration of kingbasees v8.3 to v8.6 of Jincang database (2. Compatibility of kingbasees v8.3 and v8.6)
迅为IMX6开发板QT系统创建AP热点基于RTL8723-交叉编译iptables
NAT如何配置地址转换
Design idea of room inventory in hotel reservation system database
【C】逆序字符串(俩种递归思路)
智能垃圾桶(七)——SG90舵机的介绍与使用(树莓派pico实现)
Jincang database kingbasees client Programming Interface Guide - ODBC feature support constraints
AUTOCAD——Excel表格导入CAD、CAD合并两兄弟
The computer doesn't know what to uninstall, can't open the calculator, can't edit screenshots, can't open txt files, and so on
脲酶丨Worthington杰克豆脲酶的特性及测定方案
Multi sensor fusion positioning (II) -- map based positioning