当前位置:网站首页>JS prototype trap
JS prototype trap
2022-07-01 09:18:00 【su27_ 0101】
js Prototype properties are real-time
What is real-time
Such as :
function Person(){
this.name = "mike";
}
var p1 = new Person();
p1.name; // mike
Person.prototype.age = 12;
p1.age; // 12 Real time hanging on new properties
Not reliable constructor
function Person(){
this.name = "mike";
}
Person.prototype.say = function(){
return this.name;
}
var p1 = new Person();
p1.say(); // "mike"
p1.constructor;
/*
ƒ Person(){
this.name = "mike";
}
*/
Person.prototype = {
sex: 'male'
}
p1.say();//"mike"
var p2 = new Person();
p2.say();// error;
p2.constructor; // ƒ Object() { [native code] }
Changed the Person.prototype constructor It's also changing
But the old p1 adopt __proto__ You can still visit say
How to avoid constructor The loss of
Changing prototype After that, please constructor Point back to the original constructor
function Person(){}
Person.prototype = {};
Person.prototype.constructor = Person;
边栏推荐
- LeetCode 344. Reverse string
- 集成积木报表报错 org.apache.catalina.core.StandardContext.filterStart 启动过滤器异常
- JCL and slf4j
- Latex插入的eps图片模糊解决方法
- Pain points and solutions of equipment management in large factories
- Daily practice of C language - day 80: currency change
- [ESP nanny level tutorial preview] crazy node JS server - Case: esp8266 + MQ Series + nodejs local service + MySQL storage
- [ESP nanny level tutorial preview] crazy node JS server - Case: esp8266 + DHT11 +nodejs local service + MySQL database
- 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
- Microcomputer principle - bus and its formation
猜你喜欢

Microcomputer principle - bus and its formation

Phishing identification app

3D printing Arduino four axis aircraft

计网01-物理层

Error org apache. catalina. core. StandardContext. FilterStart start filter exception
![[video game training] real topic of 2013 video game of infrared optical communication device](/img/ef/c2c45c1c6c24aed0a4e93101047372.png)
[video game training] real topic of 2013 video game of infrared optical communication device

Preparing for the Blue Bridge Cup -- bit operation

2.4 activation function

Principles of Microcomputer - internal and external structure of microprocessor

【pytorch】nn. Crossentropyloss() and nn NLLLoss()
随机推荐
Shell script - definition, assignment and deletion of variables
【pytorch】nn.AdaptiveMaxPool2d
Win7 pyinstaller reports an error DLL load failed while importing after packaging exe_ Socket: parameter error
js this丢失问题分析 及 解决方案
Imitation of Baidu search results top navigation bar effect
[pytorch learning] torch device
Flink面试题
Can diffusion models be regarded as an autoencoder?
[ESP nanny level tutorial preview] crazy node JS server - Case: esp8266 + DS18B20 temperature sensor +nodejs local service + MySQL database
【ESP 保姆级教程】疯狂毕设篇 —— 案例:基于阿里云、小程序、Arduino的WS2812灯控系统
Shell script - array definition and getting array elements
Jetson Nano 安装TensorFlow GPU及问题解决
3D printing Arduino four axis aircraft
How to effectively align team cognition
FAQ | FAQ for building applications for large screen devices
Promise asynchronous programming
Shell script - string
An overview of the design of royalties and service fees of mainstream NFT market platforms
Set the type of the input tag to number, and remove the up and down arrows
es6-顶层对象与window的脱钩