当前位置:网站首页>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边栏推荐
- 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?
- Analysis of STL source code
- Log4j 漏洞仍普遍存在?
- 零钱通项目(两个版本)含思路详解
- Software testing interview question: what is regression testing?
- 自研5G芯片商用推迟?未来4年苹果iPhone都将采用高通5G芯片
- Station B collapsed. If we were the developer responsible for the repair that night
- Recursion / backtracking (Part 1)
- Idea connects to MySQL database and performs SQL query operations
- Simple manual implementation of map
猜你喜欢

深入理解递归的方法调用(含实例迷宫问题、汉诺塔、猴子吃桃、斐波拉契、阶乘))

@Detailed introduction of requestparam annotation

Log4j 漏洞仍普遍存在,并持续造成影响

Common shortcut keys and setting methods of idea
![[question 23] Sudoku game with rotation | DFS (Beijing Institute of Technology / Beijing Institute of Technology / programming methods and practice / primary school)](/img/75/c207f4f562fd5b547c5b3134113154.jpg)
[question 23] Sudoku game with rotation | DFS (Beijing Institute of Technology / Beijing Institute of Technology / programming methods and practice / primary school)

Simple use of enum

关系型数据库的设计思想,20张图给你看的明明白白

MySQL执行过程及执行顺序

Mobilevit learning notes

聊聊 MySQL 事务二阶段提交
随机推荐
Unit-- read Excel
面向3nm及以下工艺,ASML新一代EUV光刻机曝光
@Autowired注解与@Resource注解的区别
Can JVM tuning be done with single core CPU and 1G memory?
DAY_ 4. Operation -- judge whether there is a certain data in the array -- realize array mapping (enlarge by 10 times) -- insert the array in sequence (modify bugs) -- realize array de duplication
一篇文章带你走进pycharm的世界----别再问我pycharm的安装和环境配置了!!!
@The difference between Autowired annotation and @resource annotation
The design idea of relational database is obvious to you in 20 pictures
成员方法及其传参机制
8000 word explanation of OBSA principle and application practice
Search, insert and delete of hash table
Encapsulate an array into a class
Is it safe to open an account online now? Then choose which securities to open a securities account
Log4j 漏洞仍普遍存在?
紫光展锐:2020年将有数十款基于春藤510的5G终端商用
微软商店无法下载应用,VS2019无法下载插件问题解决方案
Enumeration and annotation
Software test interview question: please say who is the best person to complete these tests, and what is the test?
2021-11-05理解main方法语法、代码块及final关键字
为什么要使用MQ消息中间件?这几个问题必须拿下