当前位置:网站首页>JS Es5 can also create constants?
JS Es5 can also create constants?
2022-06-30 16:45:00 【InfoQ】
Brief introduction
ES6letconstES6constES6ES 5 Create constant
Object.defineProperty
Basic usage
ES6constObject.definePropertyVue2Object.definePropertyObject.definePropertyObject.definePropertyObject.defineProperty(obj, prop, descriptor)- obj: The object to define the property .
- prop: The name of the property to be defined or modified or
Symbol.
- descriptor: Property descriptor to define or modify .
var LH = {}
Object.defineProperty(LH, 'name', {
value: ' Thunder monkey '
})
console.log(LH) // Output : {name: ' Thunder monkey '}
LH.name = ' Shark chilli '
console.log(LH) // Output : {name: ' Thunder monkey '}
LH.namedescriptorvaluewritablefalseLH.name = ' Shark chilli 'writabletruevar LH = {}
Object.defineProperty(LH, 'name', {
value: ' Thunder monkey ',
writable: true // Allow modification of
})
console.log(LH) // Output : {name: ' Thunder monkey '}
LH.name = ' Shark chilli '
console.log(LH) // Output : {name: ' Shark chilli '}
Create constant
LHwindowwindowObject.defineProperty(window, 'NAME', {
value: ' Thunder monkey '
})
console.log(NAME) // Output : Thunder monkey
NAME = ' Shark chilli '
console.log(NAME) // Output : Thunder monkey
window.NAME = ' Cockroach bully '
console.log(NAME) // Output : Thunder monkey
NAMEConstants can actually change values ?
valueObject.defineProperty(window, 'NAME', {
value: {
nickname: ' Thunder monkey '
}
})
console.log(NAME)
NAME.nickname = ' Shark chilli '
console.log(NAME)
Compatibility
Object.defineProperty
边栏推荐
- What is the difference between real-time rendering and pre rendering
- MySQL8.0开启远程连接权限的方法步骤
- '<', Hexadecimal value 0x3c, is an invalid problem solving
- 360 digital, ant group, etc. were selected as member units of the "business security promotion plan" of the Chinese Academy of Communications
- IndexSearch
- Halcon knowledge: matrix topic [02]
- 24:第三章:开发通行证服务:7:自定义异常(来表征程序中出现的错误);创建GraceExceptionHandler来全局统一处理异常(根据异常信息,构建对应的API统一返回对象的,JSON数据);
- 招标公告:天津市住房公积金管理中心数据库一体机及数据库软件项目(预算645万)
- Rong Lianyun launched rphone based on Tongxin UOS to create a new ecology of localization contact center
- Three development trends of enterprise application viewed from the third technological revolution
猜你喜欢

halcon知识:区域专题【07】

The new tea drinks are "dead and alive", but the suppliers are "full of pots and bowls"?

猎头5万挖我去VC

Raft介绍

MC Instruction Decoder

牛客网:乘积为正数的最长连续子数组

2022新消费半年盘点:行业遇冷,但这九个赛道依然吸金

Hundreds of lines of code to implement a JSON parser

AVIC UAV technology innovation board is listed: the fist product with a market value of 38.5 billion is pterodactyl UAV

RT-Thread 堆区大小设置
随机推荐
What is XR extended reality and what are the XR cloud streaming platforms
MySQL8.0开启远程连接权限的方法步骤
Halcon knowledge: matrix topic [02]
register_ Chrdev and CDEV_ init cdev_ Add usage differences
Mysql代理中间件Atlas安装和配置
2022蓝桥杯国赛B组-费用报销-(线性dp|状态dp)
牛客网:有多少个不同的二叉搜索树
Bc1.2 PD protocol
flink sql cdc 同步sqlserver 报错什么原因啊
Cesium-1.72 learning (add points, lines, cubes, etc.)
2022 Blue Bridge Cup group B - expense reimbursement - (linear dp| status DP)
Two methods for MySQL to open remote connection permission
招标公告:深圳市财政局数据库异地灾备项目
Siyuan notes: can you provide shortcut keys for folding all titles on the page?
备战数学建模34-BP神经网络预测2
Solution for IIS failing to load font files (*.woff, *.svg)
赛芯电子冲刺科创板:拟募资6.2亿 实控人谭健为美国籍
超 Nice 的表格响应式布局小技巧
Which direction should college students choose to find jobs after graduation?
【机器学习】K-means聚类分析