当前位置:网站首页>JS prototype inheritance can only inherit instances, not constructors
JS prototype inheritance can only inherit instances, not constructors
2022-07-01 09:18:00 【su27_ 0101】
js The prototype inherits the disadvantages of the constructor
- modify Person The constructor will affect the subclass that inherits it
function Person(){this.sex = 'man'};
function Man(){};
Man.prototype = Person;
var m1 = new Man();
m1.sex;//'man'
// modify Person The constructor will affect the subclass that inherits it
delete Person.sex;
m1.sex;//undefined
js Prototypes inherit constructor instances to avoid disadvantages
function Person(){this.sex = 'man'};
function Man(){};
Man.prototype = new Person();
Man.prototype.construct = Man;
var m1 = new Man();
m1.sex;//'man'
// modify Person The constructor does not affect the subclass that inherits it
delete Person.sex;
m1.sex;//'man'
边栏推荐
- Implementation and application of queue
- 树结构---二叉树1
- Vsync+ triple cache mechanism +choreographer
- 2.3 [kaggle dataset - dog feed example] data preprocessing, rewriting dataset, dataloader reading data
- 【pytorch】softmax函数
- Flink面试题
- Reproduced Xray - cve-2017-7921 (unauthorized access by Hikvision)
- 计网01-物理层
- 【ESP 保姆级教程】疯狂毕设篇 —— 案例:基于阿里云、小程序、Arduino的WS2812灯控系统
- 闭包实现迭代器效果
猜你喜欢

OSPF - virtual link details (including configuration commands)

Jetson Nano 安装TensorFlow GPU及问题解决

2.2 【pytorch】torchvision.transforms

How to manage fixed assets efficiently in one stop?

2.4 activation function

Jeecg restart alarm 40001

How to launch circle of friends marketing and wechat group activities

Vsync+ triple cache mechanism +choreographer

3D printing Arduino four axis aircraft

【检测技术课案】简易数显电子秤的设计与制作
随机推荐
[pytorch] softmax function
【pytorch】transforms. Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
nacos服务配置和持久化配置
Flink interview questions
樹結構---二叉樹2非遞歸遍曆
Structure de l'arbre - - - arbre binaire 2 traversée non récursive
tensorrt yolov5_ trt. Py comments
Ranking list of domestic databases in February, 2022: oceanbase regained the "three consecutive increases", and gaussdb is expected to achieve the largest increase this month
[interview brush 101] linked list
2.2 【pytorch】torchvision.transforms
Imitation of Baidu search results top navigation bar effect
Installation and use of NoSQL database
Shell script -for loop and for int loop
Shell script echo command escape character
An overview of the design of royalties and service fees of mainstream NFT market platforms
phpexcel 里 获取某一列的列表 获取某一列的字母
【pytorch】softmax函数
Shell script -if else statement
【检测技术课案】简易数显电子秤的设计与制作
Flink面试题