Proxy allows you to trap what happens when you try to get a property value off of an object and do some behavior before the value is accessed. For example, you could check the name of the property and always return a certain value or even check if the property is undefined and return some default. The options are unlimited.

"use strict"

let person = {
name: "John"
} let handler = {
get(target, key) {
if (key === "name") {
return "Mindy"
} if (Reflect.has(target, key)) {
return Reflect.get(target, key)
} return "You tried to access something undefined"
}
} person = new Proxy(person, handler) console.log(person.name) // "Mindy"
console.log(person.age) // "You tried to access something undefined"

  

最新文章

  1. amazon oa1 - search in 2D array II [Leetcode] 240
  2. 怎么样修改PHPStorm中文件修改后标签和文件名的颜色与背景色
  3. 25 uname-用于显示系统信息
  4. HTML5学习总结-08 应用缓存(Application Cache)
  5. Appium使用PageFactory初始化对象时报空指针错误
  6. PHP 5.6正式发布:新特性、及功能改进介绍
  7. Jasper_table_resolve get multiple copies of table in detail band issue
  8. javascript 工作必知(四) 类型转换
  9. AFNetWorking 对汉字部分UTF-8编码
  10. ssh密钥分发与ansible
  11. ECharts中color : function的用法(转)
  12. Nginx反向代理的基本配置
  13. linux基础之正则表达式
  14. 分布式Snowflake雪花算法
  15. LeetCode--No.006 ZigZag Conversion
  16. LINUX内核分析第七周学习总结——可执行程序的装载
  17. django rest framework跨表取值
  18. js阻止事件冒泡的两种方法
  19. Shell脚本中实现切换用户并执行命令操作【转】
  20. pymongo创建索引

热门文章

  1. input输入框内容变化实时监听
  2. kafka 名词解释(四)
  3. review代码,需要做些什么???
  4. C - Co-prime
  5. 怎么保证 redis 和 db 中的数据一致
  6. 牛客 216 C 小K的疑惑
  7. ideaIU-2019.2.exe-安装目录和设置目录结构的说明
  8. JS中逗号运算符的用法
  9. IOS 点击按钮拨号
  10. oracle中查询表中的触发器,关闭启用操作