javascript - Destructuring promice callback -


there promice in code:

req.getvalidationresult()         .then(result => {             let errors = result.array();             if (errors.length) {                 return res.status(400).json({ errors: errors });             }              return next();         }); 

i'd know there variants destructure 'result' variable on call (something .then({result.array(): errors} =>...) , not make let errors = result.array(); assignment.

i believe impossible native promise. can change code bit:

req.getvalidationresult()         .then(({array}) => array())         .then(errors => {             if (errors.length) {                 return res.status(400).json({ errors: errors });             }             return next();         }); 

or can use bluebird. has call method:

req.getvalidationresult()         .call('array')         .then(errors => {             if (errors.length) {                 return res.status(400).json({ errors: errors });             }             return next();         }); 

but in case need cast promise bluebird promise


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -