当前位置:网站首页>简单化构造函数的继承方法(二)- 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()
边栏推荐
- 分布式网络通信框架:本地服务怎么发布成RPC服务
- Tower of Hanoi II | tower of Hanoi 4 columns
- Study notes of the fifth week of sophomore year
- Employee information management system based on Web
- Flutter Event 派发
- Server memory failure prediction can actually do this!
- SPARK中 DS V2 push down(下推)的一些说明
- Network related journals and conferences in CS
- Study notes of the second week of sophomore year
- Leetcode 504. 七进制数
猜你喜欢

Data communication foundation TCPIP reference model

Learning about tensorflow (I)

The practice of OpenCV -- bank card number recognition

I finished watching this video on my knees at station B

Installation and use of cocoapods

Unstoppable, pure domestic PCs have been in place, and the monopoly of the U.S. software and hardware system has been officially broken
![[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

Due to fierce competition in the new market, China Mobile was forced to launch a restrictive ultra-low price 5g package

数通基础-STP原理

What will the new Fuzhou Xiamen railway bring to Fujian coastal areas?
随机推荐
Applet record
The charm of SQL optimization! From 30248s to 0.001s
Wechat applet learning notes 1
Due to fierce competition in the new market, China Mobile was forced to launch a restrictive ultra-low price 5g package
On the compilation of student management system of C language course (simple version)
In Net 6.0
2021 windows penetration of "Cyberspace Security" B module of Shandong secondary vocational group (analysis)
Phpexcel export Emoji symbol error
SQL Server 2008 R2 installation problems
Vs2019 configuring opencv
The use of MySQL in nodejs
Use of pclint in vs2013
Study notes of the third week of sophomore year
在.NET 6.0中配置WebHostBuilder
B站这个视频我是跪着看完的
protobuf的基本用法
Learning about opencv (1)
服务发现原理分析与源码解读
PHP executes shell script
Leetcode 504. 七进制数