Please be aware that the provided code uses a busy-wait mechanism, considered an antipattern and discouraged. This method involves a loop continually checking the system clock until the specified duration passes. While it works as a makeshift alternative, it’s crucial to use caution and explore other solutions when available.
Here’s the function for your reference:
Beware of execution time limits when running this code. Always test first.
function setTimeout(aFunction, milliseconds){
var date = new Date();
date.setMilliseconds(date.getMilliseconds() + milliseconds);
while(new Date() < date){
}
return aFunction();
}