Hello,
function declaration via let / const / var - should we strive for this?
If you declare functions in this way, you have to swap the blocks, and the result is not very readable. Code example:
-How to re-declare f-tion to be beautiful?
// Π·Π°ΠΌΠ΅Π½ΡΠ΅Ρ Π²ΡΠ΅ <div class="include">html_link</div> Π½Π° ΡΠΎΠ΄Π΅ΡΠΆΠΈΠΌΠΎΠ΅ ΡΠΊΠ°ΡΠ°Π½Π½ΠΎΠ΅ ΠΏΠΎ ΡΡΡΠ»ΠΊΠ΅ html_link function newInclude() { // ΡΠΎΠ±ΠΈΡΠ°Π΅ΠΌ Π²ΡΠ΅ ΠΈΠ½ΠΊΠ»ΡΠ΄Ρ const includes = [].slice.call(document.getElementsByClassName('include')); for (const include of includes) { const url = include.innerHTML; uploadUrl(include, url); } // ΡΠΊΠ°ΡΠΈΠ²Π°Π΅ΠΌ ΡΠΎΠ΄Π΅ΡΠΆΠΈΠΌΠΎΠ΅ Ρ url function uploadUrl(include, url) { fetch(url) .then(function(response) { return response.text(); }) .then(function(responseText) { insertInclude(include, responseText); }); } // ΡΡΠ°Π²ΠΈΠΌ ΡΠΎΠ΄Π΅ΡΠΆΠΈΠΌΠΎΠ΅ url Π²ΠΌΠ΅ΡΡΠΎ Π±Π»ΠΎΠΊΠ° include function insertInclude(include, responseText) { include.insertAdjacentHTML('afterend', responseText); include.remove(); } } <div>some html...</div> <div class="include">top/top.html</div> <div>some html...</div>