当前位置:网站首页>JS Es5 can also create constants?
JS Es5 can also create constants?
2022-06-30 16:45:00 【InfoQ】
Brief introduction
ES6
let
const
ES6
const
ES6
ES 5 Create constant
Object.defineProperty
Basic usage
ES6
const
Object.defineProperty
Vue2
Object.defineProperty
Object.defineProperty
Object.defineProperty
Object.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.name
descriptor
value
writable
false
LH.name = ' Shark chilli '
writable
true
var 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
LH
window
window
Object.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
NAME
Constants can actually change values ?
value
Object.defineProperty(window, 'NAME', {
value: {
nickname: ' Thunder monkey '
}
})
console.log(NAME)
NAME.nickname = ' Shark chilli '
console.log(NAME)
Compatibility
Object.defineProperty

边栏推荐
- Mysql8 error: error 1410 (42000): you are not allowed to create a user with grant solution
- Wechat emoticons are written into the judgment, and the OK and bomb you send may become "testimony in court"
- 2022 Blue Bridge Cup group B -2022- (01 backpack to calculate the number of schemes)
- Solution for IIS failing to load font files (*.woff, *.svg)
- 牛客网:有多少个不同的二叉搜索树
- 安全帽佩戴检测算法研究
- ArcMap operation series: 80 plane to latitude and longitude 84
- The inspiration from infant cognitive learning may be the key to the next generation of unsupervised machine learning
- 2022 Blue Bridge Cup group B - expense reimbursement - (linear dp| status DP)
- Additional: (not written yet, don't look at ~ ~ ~) corsfilter filter;
猜你喜欢
牛客网:最小花费爬楼梯
【牛客网刷题系列 之 Verilog快速入门】~ 位拆分与运算
[bjdctf2020]the mystery of ip|[ciscn2019 southeast China division]web11|ssti injection
Mysql8 error: error 1410 (42000): you are not allowed to create a user with grant solution
RT thread heap size setting
How the edge computing platform helps the development of the Internet of things
halcon知识:区域专题【07】
搬运两个负载均衡的笔记,日后省的找
今晚19:00知识赋能第2期直播丨OpenHarmony智能家居项目之控制面板界面设计
15年做糊21款硬件,谷歌到底栽在哪儿?
随机推荐
ArcMap operation series: 80 plane to latitude and longitude 84
[bjdctf2020]the mystery of ip|[ciscn2019 southeast China division]web11|ssti injection
Does flinkcdc have to be a clustered version if the monitored database is Mongo
[Verilog quick start of Niuke online question series] ~ bit splitting and operation
2020 Blue Bridge Cup group B - move bricks - (greedy sorting +01 backpack)
牛客网:最小花费爬楼梯
How to connect the Internet Reading Notes - Summary
Mysql8.0 method and steps for enabling remote connection permission
Log4j2 advanced use
dart:字符串replace相关的方法解决替换字符
Build cloud native observability capability suitable for organizations
Mathematical modeling for war preparation 33- grey prediction model 2
几百行代码实现一个 JSON 解析器
'<', Hexadecimal value 0x3c, is an invalid problem solving
Half year inventory of new consumption in 2022: the industry is cold, but these nine tracks still attract gold
华为帐号多端协同,打造美好互联生活
[unity ugui] scrollrect dynamically scales the grid size and automatically locates the middle grid
I 用c I 实现“栈”
MySQL transaction / lock / log summary
备战数学建模34-BP神经网络预测2