当前位置:网站首页>Object.defineProperty和Reflect.defineProperty的容错问题
Object.defineProperty和Reflect.defineProperty的容错问题
2022-06-24 19:28:00 【aliven1】
- Object.defineProperty,出现错误,会阻断线程,容错处理需要大量使用try…catch
- Reflect.defineProperty,可以通过Reflect.defineProperty调用结果的布尔值,直接处理容错分支
let obj = {
a:1,b:2}
//通过Object.defineProperty去操作
//#region
/* try { Object.defineProperty(obj,'c',{ get(){ return 3 } }) Object.defineProperty(obj,'c',{ get(){ return 4 } }) } catch (error) { console.log(error) } */
//#endregion
//通过Reflect.defineProperty去操作
//#region
/* const x1 = Reflect.defineProperty(obj,'c',{ get(){ return 3 } }) console.log(x1) const x2 = Reflect.defineProperty(obj,'c',{ get(){ return 4 } }) if(x2){ console.log('某某某操作成功了!') }else{ console.log('某某某操作失败了!') } */
//#endregion
// console.log('@@@')
边栏推荐
- [精选] 多账号统一登录,你如何设计?
- #国企央企结构化面试#国企就业#墨斗互动就业服务管家
- Pattern recognition - 1 Bayesian decision theory_ P1
- Debugging Analysis of Kernel panics and Kernel oopses using System Map
- (to be added) games101 job 7 improvement - knowledge you need to know to realize micro surface model
- 手动事务的几个类
- [camera Foundation (II)] camera driving principle and Development & v4l2 subsystem driving architecture
- 架构实战营 第 6 期 毕业设计
- TCP_ Nodelay and TCP_ CORK
- 使用Adb连接设备时提示设备无权限
猜你喜欢

2022国际女性工程师日:戴森设计大奖彰显女性设计实力
![[camera Foundation (I)] working principle and overall structure of camera](/img/5d/c29d636a90d01e5c3852df2a0dd833.png)
[camera Foundation (I)] working principle and overall structure of camera

(待补充)GAMES101作业7提高-实现微表面模型你需要了解的知识

力扣每日一题-第26天-496.下一个更大元素Ⅰ

【论】Deep learning in the COVID-19 epidemic: A deep model for urban traffic revitalization index

66 pitfalls in go programming language: pitfalls and common errors of golang developers

Multiplexer select

Intelligent fish tank control system based on STM32 under Internet of things

为什么生命科学企业都在陆续上云?

Advanced secret of xtransfer technology newcomers: the treasure you can't miss mentor
随机推荐
Dynamic routing protocol rip, OSPF
【吴恩达笔记】机器学习基础
(待补充)GAMES101作业7提高-实现微表面模型你需要了解的知识
Decoration home page custom full screen video playback effect GIF dynamic picture production video tutorial playback code operation settings full screen center Alibaba international station
Pattern recognition - 9 Decision tree
Functional analysis of ebpf sockops
OSI and tcp/ip model
leetcode_1470_2021.10.12
188. the best time to buy and sell stocks IV
在每个树行中找最大值[分层遍历之一的扩展]
[精选] 多账号统一登录,你如何设计?
福建省发改委福州市营商办莅临育润大健康事业部指导视察工作
memcached全面剖析–2. 理解memcached的內存存儲
Kernel Debugging Tricks
Notes_ Vlan
Memcached full profiling – 1 Fundamentals of memcached
【吴恩达笔记】多变量线性回归
图的邻接表存储 数组实现
01---两列波在相遇处发生干涉的条件
When to send the update windows message