Message from JavaScript discussions

April 2017

— And if you have cross scope references to internal members of an object anyways, you might as well just give the accessor a reference to those members instead of the symbol

Message permanent page


const readFilePromise = (filename) => new Promise((resolve, reject) => fs.readFile(filename, (err, data) => {
if (err) reject(err);
else resolve(data);

Can't use Promise.resolve instead of new Promise here

— Any control flow which relies on the promise to be resolved as a matter of some async event being finished will not work... if the promise is resolved prior to that event finishing, which would be the case if you used Promise.resolve. Should be obvious to anyone who works with them routinely

Message permanent page

— Yeah

— I mean I've used pomises in non-async situations because they are a great way out of callback hell, so theres probably very good use examples for it

Message permanent page

— Ahhh

— Why would there be callbacks in non-async situations though...

— In systems design you may have an event bus

— Like a dispatcher or other event management system

— A synchronous event bus?!

— Or, in the case of DOM nodes, state propagation

— Yes