当前位置:网站首页>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()
边栏推荐
- [Qualcomm][Network] qti服务分析
- About the declaration and definition of template functions [easy to understand]
- Controller返回JSON数据
- 面试第二家公司的面试题及答案(二)
- 【Halcon视觉】形态学腐蚀
- PTA class a 1002
- Listening freely, the next stop of online text traffic competition?
- [award-winning question] ask Judea pearl, the Turing prize winner and the father of Bayesian networks
- Tower of Hanoi II | tower of Hanoi 4 columns
- C language course design Tetris (Part 2)
猜你喜欢
随机推荐
Function templates and non template functions with the same name cannot be overloaded (definition of overloads)
Replay the snake game with C language (II) end
2022/07/25------字符串的排列
String null to empty string (what does empty string mean)
Data communication foundation telnet remote management equipment
议程速递 | 7月27日分论坛议程一览
Application of crosstab in SQL Server
移动端双指缩放事件(原生),e.originalEvent.touches
移动端H5开发常用技巧总结
Function template parameters (where are the function parameters)
PTA class a 1002
软件打不开了
INSTALL_FAILED_SHARED_USER_INCOMPATIBLE错误解决方式
图片随手机水平移动-陀螺仪。360度设置条件
Draco developed by Google and Pixar supports USD format to accelerate 3D object transmission & lt; Forward & gt;
Unit test, what is unit test and why is it so difficult to write a single test
How to write a million reading article
Employee information management system based on Web
What is wrong about the description of function templates (how to solve link format errors)
js翻页、kkpager.js翻页
![[Halcon vision] morphological expansion](/img/ce/abaca036fce5b67dfe6ac361aecfea.png)


![[Halcon vision] array](/img/29/905d93795a24538fded18d2d377e52.png)




