Seriously this the best way to start my week with, thank you!! I'm so glad to hear you fixed your problem with my article π. The code is looking good, what are you working on?
Ah, I've been working on a REST API side project (to be consumed by a React app, which I have yet to learn π). My weapon of choice is really PHP, but I started to learn Node intermittently since December. My main reason of doing so is Electron and React Native and as well as React. It's blows me away to use just one language across all stacks! And as well as PWAs (service workers operating on JS).
I have one last question though. In Javascript for Dummies blog, there's a code snippet that I'll paste below:
/* ES6 */constisMomHappy=true;// PromiseconstwillIGetNewPhone=newPromise((resolve,reject)=>{// fat arrowif(isMomHappy){constphone={brand:'Samsung',color:'black'};resolve(phone);}else{constreason=newError('mom is not happy');reject(reason);}});constshowOff=function(phone){constmessage='Hey friend, I have a new '+phone.color+' '+phone.brand+' phone';returnPromise.resolve(message);};// call our promiseconstaskMom=function(){willIGetNewPhone.then(showOff).then(fulfilled=>console.log(fulfilled))// fat arrow.catch(error=>console.log(error.message));// fat arrow};askMom();
As you can notice here, the author used 2 different syntax in returning a promise. The first one is the (resolve, reject) => arrow function style, and the second one is Promise.resolve(message). My question is, is there a "right" way of doing promises? Should one just keep it consistent or let it adjust based on one's code?
Or is it not important at all?
Also, if you noticed in my code, I didn't use fat arrow functions because I'm not too comfortable with them (yet). Is it "okay" to do this or it's really just preference and consistency?
Cool!! Don't hesitate to blog about your progress, I've yet to make an API in node but I'm sure I will need to do something like that soon.
I totally agree, JavaScript at both the client and server side is pretty damn amazing isn't it.
About the different Promise syntax examples, that is actually a really good question! The difference between the two are not that big, besides that the first one offers a clear way to reject a promise, and the second one does not. If you'd return undefined in showOff, that would probably throw a wrench in the process. Apparently there's another subtle difference but I have yet to understand this: stackoverflow.com/questions/267112... π
Personally I'm all for consistency. I like the fat arrow function and got used to how they work with this, but if you're not totally comfortable with them yet, a normal function calls is just as good!!
Seriously this the best way to start my week with, thank you!! I'm so glad to hear you fixed your problem with my article π. The code is looking good, what are you working on?
Thank you! π Your article is really good!
Ah, I've been working on a REST API side project (to be consumed by a React app, which I have yet to learn π). My weapon of choice is really PHP, but I started to learn Node intermittently since December. My main reason of doing so is Electron and React Native and as well as React. It's blows me away to use just one language across all stacks! And as well as PWAs (service workers operating on JS).
I have one last question though. In Javascript for Dummies blog, there's a code snippet that I'll paste below:
As you can notice here, the author used 2 different syntax in returning a promise. The first one is the
(resolve, reject) =>
arrow function style, and the second one isPromise.resolve(message)
. My question is, is there a "right" way of doing promises? Should one just keep it consistent or let it adjust based on one's code?Or is it not important at all?
Also, if you noticed in my code, I didn't use fat arrow functions because I'm not too comfortable with them (yet). Is it "okay" to do this or it's really just preference and consistency?
Sorry for many questions, and thanks again! βΊ
Cool!! Don't hesitate to blog about your progress, I've yet to make an API in node but I'm sure I will need to do something like that soon.
I totally agree, JavaScript at both the client and server side is pretty damn amazing isn't it.
About the different Promise syntax examples, that is actually a really good question! The difference between the two are not that big, besides that the first one offers a clear way to reject a promise, and the second one does not. If you'd return
undefined
inshowOff
, that would probably throw a wrench in the process. Apparently there's another subtle difference but I have yet to understand this: stackoverflow.com/questions/267112... πPersonally I'm all for consistency. I like the fat arrow function and got used to how they work with
this
, but if you're not totally comfortable with them yet, a normal function calls is just as good!!Thanks a lot!! π