当前位置:网站首页>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'
边栏推荐
- Tree structure --- binary tree 1
- How to realize the usage of connecting multiple databases in idel
- MT7628K eCos开发入门
- Record a redis timeout
- js原型陷阱
- 队列的实现和应用
- 记一次redis超时
- 【pytorch】2.4 卷积函数 nn.conv2d
- [ESP nanny level tutorial] crazy completion chapter - Case: ws2812 light control system based on Alibaba cloud, applet and Arduino
- js valueOf 与 toString 区别
猜你喜欢
Understanding and implementation of AVL tree
How to realize the usage of connecting multiple databases in idel
An overview of the design of royalties and service fees of mainstream NFT market platforms
樹結構---二叉樹2非遞歸遍曆
【pytorch】2.4 卷积函数 nn.conv2d
FAQ | FAQ for building applications for large screen devices
Jeecg restart alarm 40001
2.3 【kaggle数据集 - dog breed 举例】数据预处理、重写Dataset、DataLoader读取数据
Installation and use of NoSQL database
2.2 【pytorch】torchvision.transforms
随机推荐
Principles of Microcomputer - internal and external structure of microprocessor
Error org apache. catalina. core. StandardContext. FilterStart start filter exception
js变量提升(hoisting)
The jar package embedded with SQLite database is deployed by changing directories on the same machine, and the newly added database records are gone
Shell script -for loop and for int loop
Flink interview questions
Shell script echo command escape character
韦东山板子编译内核问题解决
Daily office consumables management solution
【pytorch】transforms. Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
【检测技术课案】简易数显电子秤的设计与制作
Phishing identification app
手指点击屏幕就模拟进入F11进入全屏
Redis——Lettuce连接redis集群
Which method is good for the management of fixed assets of small and medium-sized enterprises?
Is it safe to dig up money and make new shares
Flink面试题
2.4 activation function
[ESP nanny level tutorial] crazy completion chapter - Case: chemical environment system detection based on Alibaba cloud and Arduino, supporting nail robot alarm
[pytorch] 2.4 convolution function nn conv2d