当前位置:网站首页>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'
边栏推荐
猜你喜欢
集成积木报表报错 org.apache.catalina.core.StandardContext.filterStart 启动过滤器异常
An overview of the design of royalties and service fees of mainstream NFT market platforms
钓鱼识别app
树结构---二叉树2非递归遍历
dsPIC30F6014a LCD 方块显示
2022.02.15_ Daily question leetcode six hundred and ninety
Simple load balancing with Nacos
Jetson Nano 安装TensorFlow GPU及问题解决
Installation and use of NoSQL database
【pytorch】softmax函数
随机推荐
[ESP nanny level tutorial preview] crazy node JS server - Case: esp8266 + MQ Series + nodejs local service + MySQL storage
PR training notes
Naoqi robot summary 28
How to effectively align team cognition
Shell script - special variables: shell $, $*, [email protected], $$$
delete和delete[]引发的问题
Understand shallow replication and deep replication through code examples
Shell script -read command: read data entered from the keyboard
Jetson Nano 安装TensorFlow GPU及问题解决
Principle and application of single chip microcomputer timer, serial communication and interrupt system
[ESP nanny level tutorial] crazy completion chapter - Case: gy906 infrared temperature measurement access card swiping system based on the Internet of things
js原型陷阱
2022.02.15_ Daily question leetcode six hundred and ninety
Class loading
闭包实现迭代器效果
How to launch circle of friends marketing and wechat group activities
类加载
nacos服务配置和持久化配置
3D printing Arduino four axis aircraft
Leetcode daily question brushing record --540 A single element in an ordered array