当前位置:网站首页>ES6 implements the observer mode through proxy and reflection
ES6 implements the observer mode through proxy and reflection
2022-07-25 18:43:00 【RemoteDev】
// Observer mode
let queueObserve = new Set();// Observation pool
let observe = fn=>queueObserve.add(fn);// The observer
let observable=data=>new Proxy(data,{set});// Data trigger , Through the agent
function set(t,k,v,r) {
let d = Reflect.set(t,k,v,r);
// @ts-ignore
queueObserve.forEach(v=>v());// Traverse the pool and call the methods in the pool
return d;
}
// Observe the data object
let data=observable({
name:'RemoteDev',
job:'IT'
});
function print() {
console.log(`${data.name},${data.job}`);
}
observe(print);// The observer
data.name='RM';// Data changes , call observable--->set---> Traversal pool 边栏推荐
- Common file operations
- Detailed introduction and application of GaN (comprehensive and complete)
- F5: Six capabilities required for enterprise digital transformation
- What is 3DE experience platform
- 银行理财子公司蓄力布局A股;现金管理类理财产品整改加速
- Typescript反射对象Reflect使用
- [haoi2015] tree operation
- ESP32 S3 vscode+idf搭建
- 什么是hpaPaaS平台?
- 8 年产品经验,我总结了这些持续高效研发实践经验 · 研发篇
猜你喜欢

Dachang cloud business adjustment, a new round of war turn

什么是hpaPaaS平台?

终极套娃 2.0 | 云原生交付的封装

项目:串口接收—ram存储—TFT显示(完整设计)

What is 3DE experience platform

How to add EXE file to boot

How to build an enterprise level OLAP data engine for massive data and high real-time requirements?

优秀的测试/开发程序员突破,不忘初心,方得始终......

华为年内二度招聘“天才少年”;540万Twitter账号信息泄露,卖价3万美元;谷歌解雇了相信AI有意识的工程师|极客头条

推特收购舆论战,被马斯克变成了小孩吵架
随机推荐
【翻译】Logstash、Fluentd、Fluent Bit,还是Vector?如何选择合适的开源日志收集器...
n-queens problem
Yyds dry inventory interview must brush top101: reverse linked list
Practice of RTC performance automation tool in memory optimization scenario
One week activity express | in simple terms, issue 8; Meetup Chengdu station registration in progress
华为年内二度招聘“天才少年”;540万Twitter账号信息泄露,卖价3万美元;谷歌解雇了相信AI有意识的工程师|极客头条
微软Azure和易观分析联合发布《企业级云原生平台驱动数字化转型》报告
CircleIndicator组件,使指示器风格更加多样化
分享六个实用的小程序插件
[web page performance optimization] what about the slow loading speed of the first screen of SPA (single page application)?
曾拿2亿融资,昔日网红书店如今全国闭店,60家店仅剩3家
Project: serial port receiving RAM storage TFT display (complete design)
3de 回复
Optimistic lock resolution
什么是3DE体验平台
ThreadLocal夺命11连问
Address book (I)
Nc78 reverse linked list
怎么禁止使用360浏览器(怎么才能把自带的浏览器停用)
Analysis of regression problem, modeling and prediction