当前位置:网站首页>Inheritance method of simplified constructor (II) - class inheritance in ES6
Inheritance method of simplified constructor (II) - class inheritance in ES6
2022-07-26 10:27:00 【Xaivor】
stay ES6 in , The method of inheritance is more convenient , I don't say much nonsense , Go straight to the code
// Parent class
class Parent {
// Construct the properties of the parent class
constructor(name, age){
this.name = name;
this.age = age;
}
// Create the method of the parent class
say() {
alert(' My name is ' + this.name + ', I this year ' + this.age);
}
}
// Subclass
class Son extends Parent {
// Inherits the properties and methods of the parent class
constructor(name, age, sex){
// call super Method to access the constructor on the parent object
super(name, age);
// New properties
this.sex = sex;
}
// The new method
say2(){
alert(' I'm Chinese !');
}
}
// Instantiate a son1 object
let son1 = new Son(' Zhang San ', 18, ' male ')
son1.say()
son1.say2()
边栏推荐
- 简单化构造函数的继承方法(一)- 组合继承
- Data communication foundation telnet remote management equipment
- Study on the basis of opencv
- Use of pclint in vs2013
- MLX90640 红外热成像仪测温传感器模块开发笔记(六)
- Wechat official account release reminder (wechat official account template message interface)
- 404页面和路由钩子
- Learning about tensor (III)
- 【Halcon视觉】图像滤波
- 一些你不知道的 web API
猜你喜欢
Basics of data communication - basic knowledge of network
The CLOB field cannot be converted when querying Damon database
Beginner of flask framework-04-flask blueprint and code separation
【Halcon视觉】形态学腐蚀
[qualcomm][network] QTI service analysis
数据库的复习--3.SQL语言
js 获得当前时间,时间与时间戳的转换
Cause: couldn‘t make a guess for 解决方法
Review of database -- 3. SQL language
Learning about tensorflow (II)
随机推荐
【Halcon视觉】图像灰度变化
[Halcon vision] image filtering
MLX90640 红外热成像仪测温传感器模块开发笔记(六)
Li Kou daily question 917
Like, "new programmer" e-book is free for a limited time!
【Halcon视觉】图像滤波
移动端H5开发常用技巧总结
【Halcon视觉】极坐标变换
json_object_put: Assertion `jso->_ref_count > 0‘ failed.Aborted (core dumped)
我们的Web3创业项目,黄了
[C language] named type and anonymous type
Review of database -- 3. SQL language
[C language] LINQ overview
Cause: could't make a guess for solution
函数模板与同名的非模板函数不可以重载(重载的定义)
Wechat official account release reminder (wechat official account template message interface)
Beginner of flask framework-04-flask blueprint and code separation
Review of database -- 1. Overview
Unit test, what is unit test and why is it so difficult to write a single test
[Qualcomm][Network] qti服务分析