Why is argument missing in chained Map operator

六眼飞鱼酱① 提交于 2021-01-29 10:11:32

问题


I'm getting to know hyperledger composer angular apps. This piece of code that yeoman generator produces puzzle me. The add method executes return this.http.post and it returns a response object, that is chained to a map operator to convert to json output. But all references I could find to map operator show that its argument must be specified, like an arrow function (v)=> {some instructions to perform on v here});, or as an anonymous function (f(v){some instructions here});

I've seem the code below also in tutorials as a best practice to deal with response objects. Obviously map operator also accepts a function and it sends the resulting response object to whom is chained to as the argument of the `map function. Could anyone provide links to where this mechanism is explained?

import { Injectable } from '@angular/core';
import { Http, Response, Headers } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';


public add(ns: string, asset: Type): Observable<Type> {
    console.log('Entered DataService add');
    console.log('Add ' + ns);
    console.log('asset', asset);
    return this.http.post(this.actionUrl + ns, asset)
            .map(this.extractData)
            .catch(this.handleError);
}


private extractData(res: Response): any {
    return res.json();
}

来源:https://stackoverflow.com/questions/50648218/why-is-argument-missing-in-chained-map-operator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!