Perhaps the most straightforward answer is:
P.then(function(data) { return doWork('text', data); });
Or, since this is tagged ecmascript-6
, using arrow functions:
P.then(data => doWork('text', data));
I find this most readable, and not too much to write.
More Related Contents:
- How to return many Promises and wait for them all before doing other stuff
- When is the body of a Promise executed?
- ES6 Promise.all() error handle – Is .settle() needed? [duplicate]
- Why does the Promise constructor require a function that calls ‘resolve’ when complete, but ‘then’ does not – it returns a value instead?
- What is the best general practice to timeout a function in promise [closed]
- When would someone need to create a deferred?
- How to extract data out of a Promise
- Are JavaScript forever-pending promises bad?
- Why does javascript ES6 Promises continue execution after a resolve?
- ES6 Promise replacement of async.eachLimit / async.mapLimit
- Why does JavaScript Promise then handler run after other code?
- When is the body of a Promise constructor callback executed?
- How to dodge jQuery promises completely when chaining two async jQuery functions?
- Cancel a vanilla ECMAScript 6 Promise chain
- What is the order of execution in JavaScript promises?
- ES6 promise settled callback?
- multiple, sequential fetch() Promise
- How do I tell if an object is a Promise?
- How to use promise in forEach loop of array to populate an object
- Should a Promise.reject message be wrapped in Error?
- Why do I need to await an async function when it is not supposedly returning a Promise?
- How to know when all Promises are Resolved in a dynamic “iterable” parameter?
- ES6 Promises – something like async.each?
- using a fetch inside another fetch in javascript
- Why is the response object from JavaScript fetch API a promise?
- ES6 promise execution order for returned values
- Why does .then() chained to Promise.resolve() allow const declaration to be reassigned?
- Promise.all is returning an array of undefined and resolves before being done
- Weird behavior with Promise throwing “Unhandled promise rejection” error
- Promise.resolve().then vs setImmediate vs nextTick