Some observations. Certain native javascript functions are blocking. Such as the alert box. If browsers allowed users to code other blocking functions they could be no more malicious than breaking their own pages. So I don't believe that this is a security issue.
Enabling blocking functions may introduce bad design patterns. Perhaps the goal is simply to discourage sloppy design, since javascript is decidedly async. But that is a fairly opinionated design concept to build into the language itself.
The question: Is there any historical or technological reason why it is not possible to build another function? Or conversely, am I mistaken, is there some way to make other functions blocking?
Suggested Design Pattern. I think it is worth showing what I mean by a blocking function. The normal design pattern is to do:
doSomethingThatMayTakeTime();
function doSomethingThatMayTakeTime(){
//Something that takes time
callback();
}
function callback(){
//Do something you only want to do once the first function is complete
}
But there are many places in my code where there is no possible code that I want to be executed until the doSomethingThatMayTakeTime function executes. In this use scenario, why can we say:
doSomethingThatMayTakeTime();
//NextLineOfCode
function doSomethingThatMayTakeTime(){
// Blocking Code -- Prevent execution of any code outside this function until this function returns/executes its last line
//Something that takes time
}
As you can see in this specific use case one would not be crazy for thinking this is a cleaner approach. And while this may seem specific, I run across this sort of situation relatively frequently. One simple example occurs when replacing the alert box with other modal boxes.