当前位置:网站首页>How to learn object Defineproperty | an article takes you to quickly learn
How to learn object Defineproperty | an article takes you to quickly learn
2022-07-27 21:58:00 【InfoQ】
Concept
Object.defineProperty()Learning route
Defining attributes
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 .
let obj = {}
Object.defineProperty(obj, 'name', {
value: 'hello'
})
console.log(obj.name); // hellocountless
let obj = {}
Object.defineProperty(obj, 'name', {
enumerable: true,
value: 'hello'
})
for(let key in obj){
console.log(key);
}Not configurable
let obj = {}
Object.defineProperty(obj, 'name', {
enumerable: true,
value: 'hello'
})
delete obj.name
console.log(obj.name); // hellolet obj = {}
Object.defineProperty(obj, 'name', {
enumerable: true, // enumeration
configurable: true, // To configure
value: 'hello'
})
delete obj.name
console.log(obj.name); // undefinedNon rewritable
let obj = {}
Object.defineProperty(obj, 'name', {
enumerable: true, // enumeration
configurable: true, // To configure
writable: true, // rewrite
value: 'hello'
})
obj.name = 'world'
console.log(obj.name);Implement interceptors
let obj = {}
let other = ''
Object.defineProperty(obj, 'name', {
enumerable: true, // enumeration
configurable: true, // To configure
get(){ // Reading method
console.log('-----') // Logic can be handled here
return other
},
set(val){ // Setup method
other = val
}
})
obj.name = 'world' // -> set
console.log(obj.name); // -> get
// -----
// worldlet obj = {
other: '123',
get name(){
return this.other;
},
set name(val){
this.other = val;
}
}
obj.name = 456;
console.log(obj.name); // 456边栏推荐
- Nano semiconductor 65W gallium nitride (GAN) scheme was adopted by Xiaomi 10 Pro charger
- LInkedList底层源码
- Software test interview question: suppose there is a text box that requires the input of a 10 character postal code, how should the text box be divided into equivalent classes?
- 软件测试面试题:请说出这些测试最好由那些人员完成,测试的是什么?
- 高并发遇到死锁了,如何搞?
- Recursion / backtracking (Part 1)
- JVM memory model interview summary
- Internal class (detailed explanation of four internal classes)
- 软件测试面试题:什么是回归测试?
- 美司法部增加针对华为的指控,包括窃取商业秘密等16项新罪名
猜你喜欢

如何实现一个好的知识管理系统?

Encapsulate an array into a class

University of Tilburg, Federal University of the Netherlands | neural data to text generation based on small datasets: comparing the added value of two semi supervised learning approvals on top of a l

IDEA连接MySQL数据库并执行SQL查询操作

Technical practice behind bloom model: how to refine 176billion parameter model?
![[day_4-review, basic concepts of objects and arrays - 1]](/img/57/750f12d5315b682d2aeec81f39dafb.png)
[day_4-review, basic concepts of objects and arrays - 1]

@Detailed introduction of requestparam annotation
![[question 22] dungeons and Warriors (Beijing Institute of Technology / Beijing Institute of Technology / programming methods and practice / primary school)](/img/64/70fa9f47836e07dd41d9e283e50adb.jpg)
[question 22] dungeons and Warriors (Beijing Institute of Technology / Beijing Institute of Technology / programming methods and practice / primary school)

@RequestParam注解的详细介绍

MySQL执行过程及执行顺序
随机推荐
Recursion / backtracking (Part 1)
Technical practice behind bloom model: how to refine 176billion parameter model?
V2.X 同步异常,无法云端同步的帖子一大堆,同步又卡又慢
Regular expression exercise
[numerical analysis exercise] Jacobi iteration method of third-order matrix
Internal class (detailed explanation of four internal classes)
day 1 - day 4
CBAM learning notes
Enumeration and annotation
Software testing interview question: what is regression testing?
2019Q4内存厂商营收排名:三星下滑5%,仅SK海力士、美光维持增长
软件测试面试题:设计测试用例时应该考虑哪些方面,即不同的测试用例针对那些方面进行测试?
An article takes you into the world of pycharm - stop asking me about pycharm installation and environment configuration!!!
MySQL execution process and order
Huawei establishes global ecological development department: fully promote HMS global ecological construction
IDEA连接MySQL数据库并执行SQL查询操作
为什么要使用MQ消息中间件?这几个问题必须拿下
技术管理 - 一定要抓大放小
疫情之下,手机供应链及线下渠道受阻!销量骤降库存严重!
LinkedList underlying source code