当前位置:网站首页>简单化构造函数的继承方法(二)- 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()
边栏推荐
- SPARK中 DS V2 push down(下推)的一些说明
- Cloud native (36) | introduction and installation of harbor in kubernetes
- SSG framework Gatsby accesses the database and displays it on the page
- IEEE conference upload font problem
- Redis realizes the correct posture of token bucket
- Error in render: "typeerror: cannot read properties of undefined (reading 'length')" --- error when calling interface
- 【有奖提问】向图灵奖得主、贝叶斯网络之父 Judea Pearl 提问啦
- SQL Server 2008 server engine failed to start?
- Introduction to latex, EPS picture bounding box
- Study notes of the fifth week of sophomore year
猜你喜欢
Use of tabbarcontroller
Docker configuring MySQL Cluster
Data communication foundation TCPIP reference model
Vs Code configures go locale and successfully installs go related plug-ins in vscode problem: Tools failed to install
2022 zhongkepan cloud - server internal information acquisition and analysis flag
Necessary for beginners: debug breakpoint debugging skills in idea and common breakpoint skills
Solve proxyerror: CONDA cannot proceed due to an error in your proxy configuration
Draw arrows with openlayer
protobuf的基本用法
数通基础-网络基础知识
随机推荐
SQL Server 2008 R2 installation problems
Netease cloud UI imitation -- & gt; sidebar
Solve proxyerror: CONDA cannot proceed due to an error in your proxy configuration
Encapsulation of tabbarcontroller
Flask框架初学-03-模板
Network related journals and conferences in CS
面试突击68:为什么 TCP 需要 3 次握手?
The use of MySQL in nodejs
Data communication foundation TCPIP reference model
Server memory failure prediction can actually do this!
In Net 6.0
点赞,《新程序员》电子书限时免费领啦!
WARNING: [pool www] server reached pm. max_ children setting (5), consider raising it
Keeping alive to realize MySQL automatic failover
Spolicy request case
Redis realizes the correct posture of token bucket
Map key not configured and uniapp routing configuration and jump are reported by the uniapp < map >< /map > component
Azkaban [basic knowledge 01] core concepts + features +web interface + Architecture +job type (you can get started with Azkaban workflow scheduling system in one article)
On the compilation of student management system of C language course (simple version)
Data communication foundation STP principle