Is the declaration of a function in the for loop an anti-pattern, leading to some real negative consequences?

 function foo(x) { //много кода, где bar не используется for (let i = 0; i < x; i++) { (function() { function bar() { //код bar } bar(); })(); } //много кода, где bar не используется } 
  • Give an example - Igor
  • @Igor added an example - user323354 4:19 pm
  • @Igor the example was not entirely successful, I modified it - look now. - user323354 pm
  • one
    1 - why is IIFE here? To hide the bar function? 2 - yes, you will create a new function every time, if it is a cycle of a thousand elements, a new function is created a thousand times, which takes its place. Let even later GC remove it, why initially produce? - ThisMan
  • @ThisMan is IIFE here because Igor asked for an example for a common task, and I had to quickly invent it in order to portray the necessary behavior. - user323354 5:34 pm

0