当前位置:网站首页>ES6 const essence and completely immutable implementation (object.free)
ES6 const essence and completely immutable implementation (object.free)
2022-07-01 09:17:00 【su27_ 0101】
The essence
const yes es6 Defined Constant ( After the definition Cannot be changed ) sign
But not completely unalterable
- about Basic types ( Numbers character string Boolean ) Can't change
- because const What is saved is its content ( Or stack address More accurate )
- But for the The compound type ( Array object )const Save a reference address
- As long as the reference address remains unchanged, any internal properties of the object pointed to by the address can be modified at will
const arr = [];
arr.push(3);// ok
arr = [];// error
But it can be done and can't be changed at all
The key is to use Object.freeze
Implementation constants are completely immutable
var constancize = (obj) => {
Object.freeze(obj);
Object.keys(obj).forEach((key, i)=>{
// recursive For objects with sub attributes Conduct freeze
if(typeof obj[key] == 'object'){
constancize(obj[key]);
}
})
}
边栏推荐
- Win7 pyinstaller reports an error DLL load failed while importing after packaging exe_ Socket: parameter error
- 3D printing Arduino four axis aircraft
- Latex插入的eps图片模糊解决方法
- Simple load balancing with Nacos
- MySQL optimization
- 【pytorch】2.4 卷积函数 nn.conv2d
- 【ESP 保姆级教程 预告】疯狂Node.js服务器篇 ——案例:ESP8266 + DS18B20温度传感器 +NodeJs本地服务+ MySQL数据库
- 【ESP 保姆级教程】疯狂毕设篇 —— 案例:基于阿里云、小程序、Arduino的温湿度监控系统
- How to solve the problem of fixed assets management and inventory?
- Pain points and solutions of equipment management in large factories
猜你喜欢

NoSQL数据库的安装和使用

2.2 【pytorch】torchvision.transforms

Installation and use of NoSQL database

FAQ | FAQ for building applications for large screen devices

【pytorch】softmax函数

NiO zero copy

Performance improvement 2-3 times! The second generation Kunlun core server of Baidu AI Cloud was launched
![[interview brush 101] linked list](/img/52/d159bc66c0dbc44c1282a96cf6b2fd.png)
[interview brush 101] linked list

Which method is good for the management of fixed assets of small and medium-sized enterprises?

计网01-物理层
随机推荐
Principles of Microcomputer - Introduction
类加载
闭包实现迭代器效果
Reproduced Xray - cve-2017-7921 (unauthorized access by Hikvision)
Principle and application of single chip microcomputer timer, serial communication and interrupt system
[interview brush 101] linked list
pcl_ Viewer command
Installation and use of NoSQL database
【pytorch】softmax函数
Is it safe to dig up money and make new shares
Day06 branch structure and cycle (III)
Jeecg restart alarm 40001
Mysql8.0 learning record 17 -create table
2.3 【pytorch】数据预处理 torchvision.datasets.ImageFolder
【pytorch】nn.CrossEntropyLoss() 与 nn.NLLLoss()
美团2022年机试
Promise asynchronous programming
Shell script echo command escape character
【ESP 保姆级教程 预告】疯狂Node.js服务器篇 ——案例:ESP8266 + DS18B20温度传感器 +NodeJs本地服务+ MySQL数据库
es6-顶层对象与window的脱钩