当前位置:网站首页>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边栏推荐
- Who is the sanctity of the six Chinese enterprises newly sanctioned by the United States?
- 面向3nm及以下工艺,ASML新一代EUV光刻机曝光
- 软件测试面试题:在windows下保存一个文本文件时会弹出保存对话框,如果为文件名建立测试用例,等价类应该怎样划分?
- Log4j vulnerability is still widespread and continues to cause impact
- Talk about MySQL transaction two-phase commit
- Analysis of STL source code
- CocoaPods 重装
- 如何实现一个好的知识管理系统?
- Understanding of L1 regularization and L2 regularization [easy to understand]
- Technical practice behind bloom model: how to refine 176billion parameter model?
猜你喜欢

Can JVM tuning be done with single core CPU and 1G memory?

How long will it take to learn the four redis cluster solutions? I'll finish it for you in one breath

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

@RequestParam注解的详细介绍

LM NAV: robot navigation method based on large models of language, vision and behavior

Regular expression exercise

为什么要使用MQ消息中间件?这几个问题必须拿下

Idea connects to MySQL database and performs SQL query operations

一口气学完 Redis 集群方案

Analysis of STL source code
随机推荐
Software testing interview question: what is regression testing?
学完4种 Redis 集群方案要多久?我一口气给你说完
Simple manual implementation of map
Lvs+kept highly available cluster
[day_4-review, basic concepts of objects and arrays - 1]
Import word document pictures blocking and non blocking IO operations
Wechat applet live broadcast plug-in -- get temporary files (background integrated applet live broadcast)
Read Plato farm's eplato and the reason for its high premium
如何实现一个好的知识管理系统?
2019q4 memory manufacturers' revenue ranking: Samsung fell 5%, only SK Hynix and micron maintained growth
枚举和注解
Station B collapsed. If we were the developer responsible for the repair that night
Shengyang technology officially launched the remote voiceprint health return visit service system!
Under the epidemic, the mobile phone supply chain and offline channels are blocked! Sales plummeted and inventory was serious!
Encapsulate an array into a class
纳微半导体65W 氮化镓(GaN)方案获小米10 Pro充电器采用
First zhanrui 5g chip! Exposure of Hisense F50, a pure domestic 5g mobile phone: equipped with Huben T710 + chunteng 510
In addition to "adding machines", in fact, your micro service can be optimized like this
MySQL execution process and order
Up to 7.5gbps! The world's first 5nm 5g baseband snapdragon X60 release: support the aggregation of all major bands!