当前位置:网站首页>类的 prototype 属性和__proto__属性,类原型链有两条继承路线
类的 prototype 属性和__proto__属性,类原型链有两条继承路线
2022-06-11 15:51:00 【imkaifan】
类的两天继承路线:类作为一个对象的__proto__属性;Class 作为构造函数的语法糖,同时有prototype属性和__proto__属性;
(1)子类的__proto__属性,表示构造函数的继承,总是指向父类。
(2)子类prototype属性的__proto__属性,表示方法的继承,总是指向父类的prototype属性。
class Person {
constructor(name, sex) {
this.name = name;
this.sex = sex;
}
say() {
return ('lalalala' + this.name)
}
}
Person.color = 'red'
class PersonOther extends Person {
constructor(x,y) {
super(x,y)
}
}
console.log(PersonOther.__proto__ === Person) // true // 原型链形成
console.log(PersonOther.prototype.__proto__ === Person.prototype) // true // 原型链形成
console.log(PersonOther.color) // red 类集成静态属性是不给实例使用的,只是类与类之间静态属性实现了继承
let kate = new PersonOther('kate', 'woman')
console.log(kate.name, kate.sex) // kate woman
console.log(kate.color) // undefined
console.log(kate.say()) // lalalala kate
边栏推荐
- [Yugong series] June 2022 Net architecture class 076- execution principle of distributed middleware schedulemaster
- Opengauss database ODBC environment connection configuration (Windows)
- Opengauss database flashback function verification
- This "invisible" robot may be your future colleague
- Hands on, how should selenium deal with pseudo elements?
- GO語言-值類型和引用類型
- Connect to the database using GSQL
- Import data to the database? Try the copy from stdin statement
- 使用Cloud DB构建APP 快速入门-Server篇
- 使用Cloud DB构建APP 快速入门-快应用篇
猜你喜欢

Verification code is the natural enemy of automation? Ali developed a solution

PostgreSQL startup process

AI tool for cutting-edge technology exploration: analog detection

AutoRunner自动化测试工具如何创建项目-Alltesting|泽众云测试

推开混合云市场大门,Lenovo xCloud的破局之道

openGauss数据库闪回功能验证
![[0006] titre, mots clés et description de la page](/img/28/973bdb04420c9e6e9a2331663c6948.png)
[0006] titre, mots clés et description de la page

dapr 思维导图

Analysis of breadcrumb usage scenarios on websites

Collection | can explain the development and common methods of machine learning!
随机推荐
AI function of cutting-edge technology exploration: slow SQL discovery
openGauss数据库性能调优概述及实例分析
Zero foundation self-study software test, I spent 7 days sorting out a set of learning routes, hoping to help you
如何管理并发写入操作?带你快速上手
openGauss 多线程架构启动过程详解
前沿科技探究DeepSQL:库内AI算法
[daily question series]: how to test web forms?
Frontier technology exploration deepsql: in Library AI algorithm
使用Cloud DB构建APP 快速入门-快游戏篇
Easy to use GS_ Dump and GS_ Dumpall command export data
Opengauss database JDBC environment connection configuration (eclipse)
Application of AI in index recommendation
Maui introductory tutorial series (1. framework introduction)
Verification code is the natural enemy of automation? Ali developed a solution
鼻孔插灯,智商上升,风靡硅谷,3万就成
Analysis of breadcrumb usage scenarios on websites
AI4DB:人工智能之慢SQL根因分析
从屡遭拒稿到90后助理教授,罗格斯大学王灏:好奇心驱使我不断探索
收藏 |彻底搞懂感受野的含义与计算
YEF 2022昨日开幕,多网络平台全程免费直播,开启在线技术盛宴!