A Javascript Proxy object is a very interesting es6 feature, that allows you to determine behaviors whenever a property is accessed in a target object. In this lesson, you will learn how to use it to prevent users from accessing specific properties in your objects

test("Intercept property access using es6 Proxies", () => {
const obj = {
_id: "klsjdahflkastfaskfdg",
name: "Khaled"
};
const handler = {
get: (target, prop) => {
if (prop[] === "_") {
throw new TypeError("Access denied");
}
return target[prop];
},
set: (target, prop, value) => {
if (prop[] === "_") {
throw new TypeError("Access denied");
}
target[prop] = value;
return true;
}
};
const proxy = new Proxy(obj, handler); expect(() => {
proxy._id;
}).toThrow();
expect(() => {
proxy._id = "something";
}).toThrow();
});

最新文章

  1. 替换GitBlit的证书为域证书
  2. Unity 3D 中实现对物体 位置(position) 旋转(rotation) 大小(scale) 的全面控制
  3. C# 序列化(Serialize)与反序列化(Deserialize)ZZ
  4. 【POJ】【2104】区间第K大
  5. HDU 4348 To the moon 可持久化线段树,有时间戳的区间更新,区间求和
  6. javaweb学习总结十五(web开发的相关概念以及常用服务器介绍)
  7. BZOJ 2754: [SCOI2012]喵星球上的点名
  8. SPOJ694 -- DISUBSTR 后缀树组求不相同的子串的个数
  9. JMeter简单性能测试(适合初学者)
  10. Windows开机登录认证与Gina DLL
  11. hibernate的基本配置
  12. 如何正确使用const、static、extern
  13. 【一天一道LeetCode】#232. Implement Queue using Stacks
  14. 巩固java(二)----JVM堆内存结构及垃圾回收机制
  15. Android 基础一 TextView,Style样式,Activity 传值,选择CheckBox 显示密码
  16. scroll-view
  17. Java多线程系列——过期的suspend()挂起、resume()继续执行线程
  18. SQL服务器模式
  19. The Beam Model:Stream & Tables翻译(上)
  20. 20181009-8 选题 Scrum立会报告+燃尽图 07

热门文章

  1. phoronix-test-suite测试云服务器
  2. 使用Python获取计算机名,ip地址,mac地址等等
  3. ie 下input光标位置垂直不居中问题
  4. 基于iscroll实现下拉和上拉刷新
  5. 怎样简单编写一个html网页
  6. [译]lambda表达式对 SAM (单个抽象方法类)type的处理方式
  7. AC日记——Crane poj 2991
  8. Node-sqlite3多字段插入数据问题
  9. linux下重置mysql密码
  10. 洛谷 P1177 【模板】快速排序 【快速排序/multiset排序】