当前位置:网站首页>简单化构造函数的继承方法(二)- ES6中的class继承
简单化构造函数的继承方法(二)- ES6中的class继承
2022-07-26 10:15:00 【Xaivor】
在ES6中,继承的方法就更加方便了,废话不多说,直接上代码
// 父类
class Parent {
// 构造父类的属性
constructor(name, age){
this.name = name;
this.age = age;
}
// 创建父类的方法
say() {
alert('我叫' + this.name + ',我今年' + this.age);
}
}
// 子类
class Son extends Parent {
// 继承父类的属性和方法
constructor(name, age, sex){
// 调用super方法访问父对象上的构造函数
super(name, age);
// 新增属性
this.sex = sex;
}
// 新增方法
say2(){
alert('我是中国人!');
}
}
// 实例化一个son1对象
let son1 = new Son('张三', 18, '男')
son1.say()
son1.say2()
边栏推荐
- Data communication foundation STP principle
- 在.NET 6.0中配置WebHostBuilder
- Server memory failure prediction can actually do this!
- Study notes at the end of summer vacation
- Basics of data communication - basic knowledge of network
- Docker configuring MySQL Cluster
- Like, "new programmer" e-book is free for a limited time!
- 网易云UI模仿-->侧边栏
- Interview shock 68: why does TCP need three handshakes?
- In the same CONDA environment, install pytroch first and then tensorflow
猜你喜欢

Data communication foundation STP principle

论文笔记(SESSION-BASED RECOMMENDATIONS WITHRECURRENT NEURAL NETWORKS)

AirTest

2022 zhongkepan cloud - server internal information acquisition and analysis flag

Data communication foundation telnet remote management equipment

Wechat applet learning notes 1
![[award-winning question] ask Judea pearl, the Turing prize winner and the father of Bayesian networks](/img/0f/01d6e49fff80a325b667784e40bff3.png)
[award-winning question] ask Judea pearl, the Turing prize winner and the father of Bayesian networks

点赞,《新程序员》电子书限时免费领啦!

Jpg to EPS

Unstoppable, pure domestic PCs have been in place, and the monopoly of the U.S. software and hardware system has been officially broken
随机推荐
[datawhale] [machine learning] Diabetes genetic risk detection challenge
IEEE conference upload font problem
Wechat applet learning notes 1
Cloud native (36) | introduction and installation of harbor in kubernetes
Flutter Event 派发
Map key not configured and uniapp routing configuration and jump are reported by the uniapp < map >< /map > component
Principle analysis and source code interpretation of service discovery
Solve proxyerror: CONDA cannot proceed due to an error in your proxy configuration
Mysql5.7.25 master-slave replication (one-way)
regular expression
Server memory failure prediction can actually do this!
Vs Code configures go locale and successfully installs go related plug-ins in vscode problem: Tools failed to install
【有奖提问】向图灵奖得主、贝叶斯网络之父 Judea Pearl 提问啦
Nodejs service background execution (forever)
面试突击68:为什么 TCP 需要 3 次握手?
时间序列异常检测
[Qualcomm][Network] qti服务分析
Learning about opencv (2)
Azkaban [basic knowledge 01] core concepts + features +web interface + Architecture +job type (you can get started with Azkaban workflow scheduling system in one article)
Rowselection emptying in a-table