当前位置:网站首页>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
边栏推荐
- 9:第三章:电商工程分析:4:【通用模块】;(待写……)
- 牛客网:乘积为正数的最长连续子数组
- 如何得到股票开户的优惠活动?在线开户安全么?
- Go zero micro Service Practice Series (VIII. How to handle tens of thousands of order requests per second)
- mysql8报错:ERROR 1410 (42000): You are not allowed to create a user with GRANT解决办法
- 2022 Blue Bridge Cup group B -2022- (01 backpack to calculate the number of schemes)
- What is the difference between real-time rendering and pre rendering
- CVPR 2022 - Tesla AI proposed: generalized pedestrian re recognition based on graph sampling depth metric learning
- MC Instruction Decoder
- 2020蓝桥杯国赛B组-搬砖-(贪心排序+01背包)
猜你喜欢

新茶饮“死去活来”,供应商却“盆满钵满”?

【机器学习】K-means聚类分析

Tencent two sides: @bean and @component are used on the same class. What happens?

腾讯二面:@Bean 与 @Component 用在同一个类上,会怎么样?

Symantec electronic sprint technology innovation board: Tan Jian, the actual controller, is an American who plans to raise 620million yuan
Mysql8 error: error 1410 (42000): you are not allowed to create a user with grant solution

BC1.2 PD协议
![[activity registration] it's your turn to explore the yuan universe! I will be waiting for you in Shenzhen on July 2!](/img/cf/6fc5f7cafbdc5e165eb119b9b41cd9.jpg)
[activity registration] it's your turn to explore the yuan universe! I will be waiting for you in Shenzhen on July 2!

Installing jupyter notebook under Anaconda

云技能提升好伙伴,亚马逊云师兄今天正式营业
随机推荐
MicroBlaze serial port learning · 2
IndexSearch
Bc1.2 PD protocol
腾讯二面:@Bean 与 @Component 用在同一个类上,会怎么样?
Solution for IIS failing to load font files (*.woff, *.svg)
2022蓝桥杯国赛B组-费用报销-(线性dp|状态dp)
牛客网:乘积为正数的最长连续子数组
Wechat emoticons are written into the judgment, and the OK and bomb you send may become "testimony in court"
Installing jupyter notebook under Anaconda
【活动报名】探秘元宇宙,就差你了!7月2号我在深圳现场等你!
数据挖掘知识点整理(期末复习版)
Half year inventory of new consumption in 2022: the industry is cold, but these nine tracks still attract gold
猎头5万挖我去VC
中国传奇教授李泽湘,正在批量制造独角兽
如何得到股票开户的优惠活动?在线开户安全么?
Halcon knowledge: regional topics [07]
Mathematical modeling for war preparation 35 time series prediction model
dart:字符串replace相关的方法解决替换字符
Create statement for Oracle export view
9:第三章:电商工程分析:4:【通用模块】;(待写……)