当前位置:网站首页>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]);
}
})
}
边栏推荐
- Shell script -if else statement
- Mise en œuvre simple de l'équilibrage de la charge par nacos
- laravel postman 提交表单出现419错误。2020年7月6日记。
- 【ESP 保姆级教程】疯狂毕设篇 —— 案例:基于阿里云和Arduino的化学环境系统检测,支持钉钉机器人告警
- FAQ | FAQ for building applications for large screen devices
- js原型陷阱
- es6-顶层对象与window的脱钩
- 【电赛训练】红外光通信装置 2013年电赛真题
- 计网01-物理层
- 类加载
猜你喜欢
![2.3 [pytorch] data preprocessing torchvision datasets. ImageFolder](/img/19/cce8d8a7cdcb1021166c46adf803c1.png)
2.3 [pytorch] data preprocessing torchvision datasets. ImageFolder

Nacos service configuration and persistence configuration

Preparing for the Blue Bridge Cup -- bit operation

An overview of the design of royalties and service fees of mainstream NFT market platforms

Performance improvement 2-3 times! The second generation Kunlun core server of Baidu AI Cloud was launched

树结构---二叉树2非递归遍历

2.4 激活函数

Redis -- lattice connects to redis cluster

How to solve the problem of fixed assets management and inventory?

3D打印Arduino 四轴飞行器
随机推荐
Daily office consumables management solution
js原型继承仅可继承实例而非构造器
Niuke monthly race 22 tree sub chain
FAQ | FAQ for building applications for large screen devices
[ESP nanny level tutorial preview] crazy node JS server - Case: esp8266 + DS18B20 temperature sensor +nodejs local service + MySQL database
【pytorch学习】torch.device
delete和delete[]引发的问题
SDN_简单总结
Nacos service configuration and persistence configuration
Shell script -if else statement
Principle and application of single chip microcomputer timer, serial communication and interrupt system
SDN_ Simple summary
Serialization, listening, custom annotation
【ESP 保姆级教程】疯狂毕设篇 —— 案例:基于物联网的GY906红外测温门禁刷卡系统
OSPF - virtual link details (including configuration commands)
2.3 【kaggle数据集 - dog breed 举例】数据预处理、重写Dataset、DataLoader读取数据
如何高效拉齐团队认知
Understanding and implementation of AVL tree
【pytorch】nn. Crossentropyloss() and nn NLLLoss()
PR training notes