https:\/\/www.youtube.com\/watch?v=uQ1zhJHclvs<\/a><\/p>\n\n\n\nfunction getMeData(ob) {\n [10,20,30].forEach(ob.next)\n}\ngiveMeData => subscribe(ob)\n\nconst observable = {\n subscribe: (ob) {\n [10,20,30].forEach(ob.next)\n }\n}\n\/\/ setter => setter\nfunction map(transform) {\n const inputObservable = this\n \n const outputObservable = createObservable(function subscribe(observe) {\n inputObservable.subscribe({\n next(val) {\n const y = transform(val)\n observe.next(y)\n },\n err(error) {\n console.error(error)\n },\n complete() {\n console.log('done')\n }\n })\n })\n return outputObservable\n}\n\nfunction filter(condition) {\n const inputObservable = this\n \n const outputObservable = createObservable(function subscribe(observe) {\n inputObservable.subscribe({\n next(val) {\n if(condition(val)){\n observe.next(val)\n }\n },\n err(error) {\n console.error(error)\n },\n complete() {\n console.log('done')\n }\n })\n })\n return outputObservable\n}\n\n\nvar createObservable = function(subscribe) {\n return ({\n subscribe: subscribe,\n map: map,\n filter: filter\n })\n}\n\nvar observe = {\n next(val) {\n console.log(val)\n },\n err(error) {\n console.error(error)\n },\n complete() {\n console.log('done')\n }\n}\n\nvar arrayObservable = createObservable(function subscribe(ob) {\n [10,20,30].forEach(ob.next)\n ob.complete()\n})\n\narrayObservable \/\/ {subscribe: function subscribe(ob){...}, map: function map(transform){...}}\n.map(val => val \/ 10) \/\/ \u8fd4\u56de\u65b0\u7684observable\u5bf9\u8c61 {subscribe: function subscribe(ob){next(val): y = transform(val) inputObservable.next(y), ...}, map: fn}\n.filter(val => val !== 2) \n.subscribe(observe) \/\/\u65b0\u7684observable\u5bf9\u8c61\u91cc\u9762subscribe<\/code><\/pre>\n\n\n\n- subscribe<\/li>
- filterObservable<\/li>
- mapObservable<\/li>
- arrayObservable<\/li>
- arrayObservable.bsubscribe(ob)<\/li>
- ob.next<\/li>
- mapObserve.next()<\/li>
- filterObserve.next()<\/li>
- arrayfilterObserve.next()<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"
https:\/\/www.youtube.com\/w …<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/localhost\/wp-json\/wp\/v2\/posts\/94"}],"collection":[{"href":"http:\/\/localhost\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/localhost\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/localhost\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/localhost\/wp-json\/wp\/v2\/comments?post=94"}],"version-history":[{"count":0,"href":"http:\/\/localhost\/wp-json\/wp\/v2\/posts\/94\/revisions"}],"wp:attachment":[{"href":"http:\/\/localhost\/wp-json\/wp\/v2\/media?parent=94"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/localhost\/wp-json\/wp\/v2\/categories?post=94"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/localhost\/wp-json\/wp\/v2\/tags?post=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}