当前位置:网站首页>简单化构造函数的继承方法(二)- 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()
边栏推荐
- Wechat applet learning notes 2
- Study notes of the second week of sophomore year
- Cloud native (36) | introduction and installation of harbor in kubernetes
- Uniapp "no mobile phone or simulator detected, please try again later" and uniapp custom components and communication
- Azkaban【基础知识 01】核心概念+特点+Web界面+架构+Job类型(一篇即可入门Azkaban工作流调度系统)
- Transform between tree and array in JS (hide the children field if the child node of the tree is empty)
- 服务发现原理分析与源码解读
- 反射机制的原理是什么?
- 数据库的复习--1.概述
- Flutter Event 派发
猜你喜欢

数通基础-网络基础知识

Like, "new programmer" e-book is free for a limited time!

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

Docker configuring MySQL Cluster

I finished watching this video on my knees at station B

Solve proxyerror: CONDA cannot proceed due to an error in your proxy configuration
![[fluorescent character effect]](/img/05/4f4c24c787881e073919b63a6864cf.jpg)
[fluorescent character effect]

如何写一篇百万阅读量的文章
![Uniapp common error [wxml file compilation error]./pages/home/home Wxml and using MySQL front provided by phpstudy to establish an independent MySQL database and a detailed tutorial for independent da](/img/21/5dceab9815b503f0b62d26a430d7eb.png)
Uniapp common error [wxml file compilation error]./pages/home/home Wxml and using MySQL front provided by phpstudy to establish an independent MySQL database and a detailed tutorial for independent da

Data communication foundation STP principle
随机推荐
The problem of four columns of Hanoi Tower
Due to fierce competition in the new market, China Mobile was forced to launch a restrictive ultra-low price 5g package
分布式网络通信框架:本地服务怎么发布成RPC服务
Common errors when starting projects in uniapp ---appid
面试突击68:为什么 TCP 需要 3 次握手?
Interview shock 68: why does TCP need three handshakes?
Leetcode 504. Hex number
Applet record
Wechat applet learning notes 1
Basic usage of protobuf
C language course design Tetris (Part 2)
Data communication foundation STP principle
数据库的复习--3.SQL语言
Learning about tensorflow (I)
Sqoop【环境搭建 01】CentOS Linux release 7.5 安装配置 sqoop-1.4.7 解决警告并验证(附Sqoop1+Sqoop2最新版安装包+MySQL驱动包资源)
服务发现原理分析与源码解读
The charm of SQL optimization! From 30248s to 0.001s
About automatic operation on Web pages
Use of tabbarcontroller
SQL Server 2008 server engine failed to start?