Observable
class Reminder { constructor(behavior){ this.behavior = behavior; } remind(cb) { this.behavior(cb) } } let reminder = new Reminder((cb)=>{ cb.next(); cb.error(); cb.complete(); }); reminder.remind({ next: () => console.log('next'), error: () => console.log('error'), complete: () => console.log('complete') }); // class Observable{ constructor(behavior){ this.behavior = behavior; } subscribe(observer){ this.behavior(observer); } } const obs$ = new Observable((cb)=>{ cb.next(1); cb.error(); cb.complete(); }); const observer = { next: v => console.log('next',v), error: () => console.log('error'), complete: () => console.log('complete') } obs$.subscribe(observer)
作者:scqilin
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。