当前位置:网站首页>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'
边栏推荐
- [pytorch] softmax function
- Class loading
- 【pytorch】2.4 卷积函数 nn.conv2d
- Shell script -if else statement
- Simple load balancing with Nacos
- 樹結構---二叉樹2非遞歸遍曆
- OSPF - virtual link details (including configuration commands)
- How to manage fixed assets well? Easy to point and move to provide intelligent solutions
- Leetcode daily question brushing record --540 A single element in an ordered array
- 足球篮球体育比赛比分直播平台源码/app开发建设项目
猜你喜欢

樹結構---二叉樹2非遞歸遍曆

Redis -- lattice connects to redis cluster

计网01-物理层

How to manage fixed assets well? Easy to point and move to provide intelligent solutions

Phishing identification app

Pain points and solutions of equipment management in large factories

nacos简易实现负载均衡

An overview of the design of royalties and service fees of mainstream NFT market platforms

Mysql 优化

How to realize the usage of connecting multiple databases in idel
随机推荐
NiO zero copy
Jetson Nano 安装TensorFlow GPU及问题解决
美团2022年机试
Shell script - positional parameters (command line parameters)
Reproduced Xray - cve-2017-7921 (unauthorized access by Hikvision)
JCL and slf4j
Redis——Lettuce连接redis集群
微信小程序 webview 禁止页面滚动,同时又不影响业务内overflow的滚动的实现方式
Key points of NFT supervision and overseas policies
Nacos service configuration and persistence configuration
钓鱼识别app
Design and manufacture of simple digital display electronic scale
nacos簡易實現負載均衡
集成积木报表报错 org.apache.catalina.core.StandardContext.filterStart 启动过滤器异常
PR training notes
Short circuit operator lazy evaluation
Win7 pyinstaller reports an error DLL load failed while importing after packaging exe_ Socket: parameter error
js this丢失问题分析 及 解决方案
Jeecg restart alarm 40001
2.4 激活函数