如何在Javascript中创建自定义异步函数?

I know that to create an asynchronous function all we need is to call an asynchronous function inside it like setTimeout() and passing a callback.

但是如何在不使用任何预建函数的情况下本机创建该代码呢?

I know that functions that query a database have an asynchronous behavior, how do they do that without using something like setTimeout() in their original implementation ?