当前位置:网站首页>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;
边栏推荐
- 【pytorch】transforms. Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
- Redis source code learning (29), compressed list learning, ziplist C (II)
- [ESP nanny level tutorial preview] crazy node JS server - Case: esp8266 + MQ Series + nodejs local service + MySQL storage
- Log4j log framework
- Tree structure --- binary tree 1
- Error org apache. catalina. core. StandardContext. FilterStart start filter exception
- Flink interview questions
- [interview brush 101] linked list
- 樹結構---二叉樹2非遞歸遍曆
- FAQ | FAQ for building applications for large screen devices
猜你喜欢
![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

Principles of Microcomputer - internal and external structure of microprocessor

Simple load balancing with Nacos

2.3 【kaggle数据集 - dog breed 举例】数据预处理、重写Dataset、DataLoader读取数据

Mise en œuvre simple de l'équilibrage de la charge par nacos

How to manage fixed assets efficiently in one stop?

2.4 activation function

Understanding and implementation of AVL tree

Pain points and solutions of equipment management in large factories

Pain points and solutions of fixed assets management of group companies
随机推荐
The jar package embedded with SQLite database is deployed by changing directories on the same machine, and the newly added database records are gone
JS原型链
Principle and application of single chip microcomputer timer, serial communication and interrupt system
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
Jetson nano installs tensorflow GPU and problem solving
【ESP 保姆级教程】疯狂毕设篇 —— 案例:基于阿里云、小程序、Arduino的温湿度监控系统
js valueOf 与 toString 区别
LogBack
PR training notes
【ESP 保姆级教程 预告】疯狂Node.js服务器篇 ——案例:ESP8266 + DHT11 +NodeJs本地服务+ MySQL数据库
【pytorch学习】torch.device
OSPF - virtual link details (including configuration commands)
Set the type of the input tag to number, and remove the up and down arrows
NoSQL数据库的安装和使用
An overview of the design of royalties and service fees of mainstream NFT market platforms
计网01-物理层
Tree structure -- binary tree 2 non recursive traversal
Jetson Nano 安装TensorFlow GPU及问题解决
美团2022年机试