当前位置:网站首页>ES6 advanced - inherit parent class attributes with constructors
ES6 advanced - inherit parent class attributes with constructors
2022-07-26 02:28:00 【setTimeout()】
One 、call Function function
(1) Call function
<body>
<script>
function sy() {
console.log('sy');
}
sy.call();
</script>
</body>Output results :sy
(2) Change function this Point to
<body>
<script>
function sy(x, y) {
console.log('sy');
console.log(this);
console.log(x + y);
}
var obj = {
name: 'oliver'
}
sy.call(obj, 1, 2);
</script>
</body>Output results :

Two 、 Using constructor to inherit parent class attribute
The core principle : adopt call() Method puts the this To subclass this, In this way, the subclass can inherit the attributes of the parent class
<body>
<script>
function Father(uname, age) {
this.uname = uname;
this.age = age;
}
function Son(uname, age) {
Father.call(this, uname, age);
}
var son = new Son('son', 18);
console.log(son);
</script>
</body>Output results :
![]()
边栏推荐
- [pyqt5 packaged as exe]
- 增删改查业务的快速上手
- [C] Explain language file operation in detail
- 本地仓库导致的报错
- Keil's operation before programming with C language
- Is the securities account presented by qiniu true? How to open it safely and reliably?
- 19_请求表单与文件
- JS get the time composition array of two time periods
- 2. Login - verification code function and saving login status
- Monitoring of debezium synchronization debezium
猜你喜欢

TCP three handshakes and four waves

Ti am335x industrial control module uses the Debian system of beaglebone (BBB)

Postman报Json序列化错误

1. Mx6ul core module use serial RTC test (XII)

TCP三次握手四次挥手

eslint常见报错集合

Implementation of Ti am335x industrial control module network and file system nfs

ES6高级-利用构造函数继承父类属性

c# 单元测试

图解B+树的插入过程
随机推荐
MySQL建Websites数据表
关于mysql的问题,希望个位能帮一下忙
scipy.sparse.csr_ matrix
1. Mx6ul core module uses serial can and buzzer test (XI)
记录之目标检测NMS(非极大值抑制)
Primary key b+ tree, secondary index b+ tree and corresponding query process analysis
TCP三次握手四次挥手
18. Delete the penultimate node of the linked list
scipy.sparse.vstack
i. Mx6ull snvs power domain GPIO status hold verification
增删改查业务的快速上手
MySQL(4)
Get hours, minutes and seconds
Pinia plugin persist, a data persistence plug-in of Pinia
Be careful about bitmap, the "memory Assassin"~
信息系统项目管理师---第十章沟通管理和干系人管理历年考题
必会面试题:1.浅拷贝和深拷贝_深拷贝
Overview of pytoch's API
Recorded target detection NMS (non maximum suppression)
流形学习、、