Maybe the point of the article was to show how simple it is to wrap everything in a promise, but starting with the original:
function getRollNumberFromName(studentName) { return new Promise(function(resolve, reject) { fn_to_get_roll_number_from_db(studentName) .then((rollNumber) => { resolve(rollNumber); }) .catch((err) => { reject(err); }); }); }
And combining with your suggestion (and doing the same with reject):
function getRollNumberFromName(studentName) { return new Promise(function(resolve, reject) { fn_to_get_roll_number_from_db(studentName) .then(resolve) .catch(reject); }); }
We can see that the then is just returning the value from the original promise and the catch is also just rejecting with the already rejected value. That means we're just returning the original promise, which can be simplified to:
function getRollNumberFromName(studentName) { return fn_to_get_roll_number_from_db(studentName); }
Which is just the fn_to_get_roll_number_from_db function.
fn_to_get_roll_number_from_db
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Maybe the point of the article was to show how simple it is to wrap everything in a promise, but starting with the original:
And combining with your suggestion (and doing the same with reject):
We can see that the then is just returning the value from the original promise and the catch is also just rejecting with the already rejected value. That means we're just returning the original promise, which can be simplified to:
Which is just the
fn_to_get_roll_number_from_db
function.