Saturday 29 September 2018

newbie question about nodejs classes and promises

Hey guys!Really sorry for this newbie question about nodejs. I've started looking into how classes are done in nodejs and I had a question.Are there some general guidelines for when to use or not use promises in a class? For example, would it be bad practice for a class method to return a promise? I was looking around at example code for classes in nodejs and it doesn't seem that this is something people do.For example, is there anything wrong with this:class User {constructor(name) { this.name = name; }do_a_promise() { return new Promise(function(fulfill, reject) { console.log("hello world"); fulfill(); }); }This is just a dumb example but is there any reason that you would definitely not want a method to return a promise?edit: sorry for the formatting. I couldn't get the formatting to look quite right.

Submitted September 30, 2018 at 01:05AM by thenewstampede

No comments:

Post a Comment