Reputation: 701
I've read that it is not safe to use document.write inside an async function since it can delete all you have. But, is it safe to have:
(function() {
function one() {
document.write('whatever here');
}
one();
})();
I'm not a fan of document.write, but I'm looking into an external JS having this.
Upvotes: 2
Views: 105
Reputation: 28870
Yes, that's perfectly fine, assuming that the code is being run during the page load.
There's nothing about the IIFE that would make this asynchronous.
Your code could be rewritten as:
function one() {
document.write('whatever here');
}
function main() {
one();
}
main();
Other than introducing more function names, this is exactly the same thing. It may be more apparent this way that there's no asynchronous code here.
Upvotes: 1