Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

strange syntax in javascript about the argument

any one can give some explanation about the following syntax:

clear: function(callback?: ?(error: ?Error) => void): Promise {
  // balabala here
}

anyone can help?

like image 682
Damon Yuan Avatar asked Jul 01 '26 16:07

Damon Yuan


1 Answers

They're flow declarations (http://flowtype.org) where there may be callback and/or an error and it returns a Promise.

You can call clear() for instance:

/* flow */
...
    clear((data) => {
      ...do something with *data*, like resolve the promise ...
    }, (error) => {
      ...handle *error*, like reject the promise ...
    })
...

and it will return you a Promise object.

like image 67
Samuli Hakoniemi Avatar answered Jul 04 '26 04:07

Samuli Hakoniemi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!