当前位置:网站首页>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;
边栏推荐
- 3D printing Arduino four axis aircraft
- Youqitong PE toolbox [vip] v3.7.2022.0106 official January 22 Edition
- Short circuit operator lazy evaluation
- 【pytorch】2.4 卷积函数 nn.conv2d
- nacos简易实现负载均衡
- 【pytorch】nn.CrossEntropyLoss() 与 nn.NLLLoss()
- 利用闭包实现私有变量
- The fixed assets management system enables enterprises to dynamically master assets
- Exception handling of classes in C #
- Learning practice: comprehensive application of cycle and branch structure (II)
猜你喜欢

How to manage fixed assets well? Easy to point and move to provide intelligent solutions
![[pytorch] 2.4 convolution function nn conv2d](/img/eb/382a00af5f88d5954f10ea76343d6e.png)
[pytorch] 2.4 convolution function nn conv2d

Ape anthropology topic 20 (the topic will be updated from time to time)

Principles of Microcomputer - internal and external structure of microprocessor

【检测技术课案】简易数显电子秤的设计与制作

Nacos service configuration and persistence configuration
![2.3 [kaggle dataset - dog feed example] data preprocessing, rewriting dataset, dataloader reading data](/img/6e/d8ef618127ac492f5142f7b600266d.png)
2.3 [kaggle dataset - dog feed example] data preprocessing, rewriting dataset, dataloader reading data

Simple load balancing with Nacos

Phishing identification app

FAQ | FAQ for building applications for large screen devices
随机推荐
NiO zero copy
[interview brush 101] linked list
ES6 decoupling top-level objects from windows
js原型陷阱
es6-顶层对象与window的脱钩
The fixed assets management system enables enterprises to dynamically master assets
Mysql 优化
Shell script case in and regular expressions
Graduation season, I want to tell you
Implementation and application of queue
I use flask to write the website "one"
[ESP nanny level tutorial preview] crazy node JS server - Case: esp8266 + DHT11 +nodejs local service + MySQL database
Reproduced Xray - cve-2017-7921 (unauthorized access by Hikvision)
手指点击屏幕就模拟进入F11进入全屏
Ape anthropology topic 20 (the topic will be updated from time to time)
nacos简易实现负载均衡
闭包实现迭代器效果
SDN_简单总结
Understanding and implementation of AVL tree
How to launch circle of friends marketing and wechat group activities