V
V
Vladimir Tyutimov2016-02-01 09:51:26
JavaScript
Vladimir Tyutimov, 2016-02-01 09:51:26

What is this syntax?

Good afternoon!
There is a function: https://jsfiddle.net/3drhqapa/
Returns a promise.
I did it as in the tutorial: https://learn.javascript.ru/promise#promise-resolv...
The thing is, here is this piece of code:

video_get('-648623423','').then(
        response    => {console.log("Success" + response)},
        error       => {console.log("ERROR:" + error)}
    );

My PHPStorm highlights and says: This inspection reports expression statements which are not assignments or calls. Such statements have no dubious semantics, are normally the result of programmer error.
What does this mean and how to fix it?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Igor Kalashnikov, 2016-02-01
@BidiBom

This is most likely babel, after compilation the output will be:

video_get('-64866375', '').then(function (response) {
        console.log("Success" + response);
}, function (error) {
        console.log("ERROR:" + error);
});

here is the link to the REPL

K
Kovalsky, 2016-02-01
@lazalu68

This is the syntax of ECMAScript 2015. I think you have everything written correctly: then() takes two arguments, the first of which is a function that will be executed if the promise is fulfilled, and the second is a function that will be executed if an error occurs. The functions are given as arrows. This construct even works: it tells me that an error has occurred, because $http does not exist.
Maybe PHPStorm thinks it's bad when the anonymous function is not immediately executed and passed to some variable. Look here , it seems to me there is the same kind of error.
In general, this is not even an error, but a warning, isn't it? You can actually score on it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question