Quick question about promise flattening

So this works:

    .then(() => {
        return Facebook.getLoginStatus();
    .then() ... more promise stuff.

This doesn’t work:

    .then() ... more promise stuff.

Error: TypeError: null is not an object (evaluating ‘t.pluginRef’)

I don’t really understand why this error happens, as getLoginStatus returns a promise. Shouldn’t this work? I hate wrapping functions in anonymous functions, like in the first example. It’s redundant and ugly.

It’s not really about promises, it’s about function invocation and this.

You can write

.then(() => Facebook.getLoginStatus())

1 Like

I suppose that would work, however Angular2’s own Hero example has this code:

  getHeroes (): Observable<Hero[]> {
    return this.http.get(this.heroesUrl)

  private extractData(res: Response) {
    let body = res.json();
    return body.data || { };

Notice no arrow functions.

Should I take this to stackoverflow? :slight_smile:

Uh? Is that supposed to be a threat of some sort? :smile: You can ask wherever you want of course. I thought I already provided an answer though.

1 Like

No no, but notice my reply, where I reference the angular hero tutorial.

Notice that extractData in that example might as well be a static method, in that it doesn’t care what this is. Perhaps that’s not true of the method you are using.

1 Like