Yet another better way to organize async functions in JavaScript utility function.
Previously, to be able to tell an async function at first glance, I put a Task prefix on the function name.
js |
---|
function TaskRefreshList() { // ... } |
Cons:
- It makes the function name longer.
- Doesn't make sense on a utility function that consist only async functions.
I think I've found a new way to organize async function without avoid above cons. All I had to do is to group async function as a task object.
js |
---|
let ui = (function() { let SELF = { task: { updateItem, } }; function updateItem() { // todo() } return SELF; })(); |
This way I can keep the name short but still able to tell async function or not.
Improving from Here
So, I ended up not using this approach as it requires me to selectively group async functions, which is quite a cumbersome process.
The next approach takes the initial writing and improves from it, i.e. by using "-Async" postfix instead of "Task-" prefix.
https://vanillawebdev.blogspot.com/2024/03/naming-the-async-function-part-2.html https://www.blogger.com/blog/post/edit/8166404610182826392/4161510298093757977 https://www.blogger.com/blog/page/edit/8166404610182826392/4161510298093757977Naming The Async Function - Part 2
Yet another better way to organize async functions in JavaScript utility function.
Previously, to be able to tell an async function at first glance, I put a Task prefix on the function name.
js |
---|
function TaskRefreshList() { // ... } |
Cons:
- It makes the function name longer.
- Doesn't make sense on a utility function that consist only async functions.
I think I've found a new way to organize async function without avoid above cons. All I had to do is to group async function as a task object.
js |
---|
let ui = (function() { let SELF = { task: { updateItem, } }; function updateItem() { // todo() } return SELF; })(); |
This way I can keep the name short but still able to tell async function or not.
Improving from Here
So, I ended up not using this approach as it requires me to selectively group async functions, which is quite a cumbersome process.
The next approach takes the initial writing and improves from it, i.e. by using "-Async" postfix instead of "Task-" prefix.
Comments
Post a Comment