当前位置:网站首页>js原型继承仅可继承实例而非构造器
js原型继承仅可继承实例而非构造器
2022-07-01 09:13:00 【su27_0101】
js原型继承继承构造器带来的缺点
- 修改Person构造器会影响到继承他的子类
function Person(){this.sex = 'man'};
function Man(){};
Man.prototype = Person;
var m1 = new Man();
m1.sex;//'man'
// 修改Person构造器会影响到继承他的子类
delete Person.sex;
m1.sex;//undefined
js原型继承继承构造器实例避免缺点
function Person(){this.sex = 'man'};
function Man(){};
Man.prototype = new Person();
Man.prototype.construct = Man;
var m1 = new Man();
m1.sex;//'man'
// 修改Person构造器不会影响到继承他的子类
delete Person.sex;
m1.sex;//'man'
边栏推荐
- Understand shallow replication and deep replication through code examples
- [interview brush 101] linked list
- SDN_ Simple summary
- 【pytorch】nn.AdaptiveMaxPool2d
- Shell script - definition, assignment and deletion of variables
- Pain points and solutions of fixed assets management of group companies
- Redis -- lattice connects to redis cluster
- Microcomputer principle - bus and its formation
- Is it safe to dig up money and make new shares
- 【pytorch】nn. AdaptiveMaxPool2d
猜你喜欢
【检测技术课案】简易数显电子秤的设计与制作
樹結構---二叉樹2非遞歸遍曆
足球篮球体育比赛比分直播平台源码/app开发建设项目
Mise en œuvre simple de l'équilibrage de la charge par nacos
Performance improvement 2-3 times! The second generation Kunlun core server of Baidu AI Cloud was launched
FreeRTOS learning easy notes
2.2 【pytorch】torchvision.transforms
NoSQL数据库的安装和使用
dsPIC30F6014a LCD 方块显示
Implementation and application of queue
随机推荐
3D printing Arduino four axis aircraft
Jetson nano installs tensorflow GPU and problem solving
树结构---二叉树1
2.3 【pytorch】数据预处理 torchvision.datasets.ImageFolder
Installing Oracle EE
nacos服务配置和持久化配置
[ESP nanny level tutorial preview] crazy node JS server - Case: esp8266 + MQ Series + nodejs local service + MySQL storage
Bird recognition app
The jar package embedded with SQLite database is deployed by changing directories on the same machine, and the newly added database records are gone
SDN_ Simple summary
[ESP nanny level tutorial] crazy completion chapter - Case: temperature and humidity monitoring system based on Alibaba cloud, applet and Arduino
Jetson Nano 安装TensorFlow GPU及问题解决
Differences among tasks, threads and processes
【pytorch】transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
【ESP 保姆级教程】疯狂毕设篇 —— 案例:基于阿里云、小程序、Arduino的温湿度监控系统
[pytorch] softmax function
I use flask to write the website "one"
通过 代码实例 理解 浅复制 与 深复制
Shell script - string
Why is the Ltd independent station a Web3.0 website!