Advertisement
elena1234

Closure (JavaScript)

Nov 23rd, 2021
1,202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getArticleGenerator(articles) {
  2.     let content = document.getElementById('content');
  3.     let index = 0;
  4.  
  5.     return function () {
  6.         if (index < articles.length) {
  7.             let newArticle = document.createElement('article');
  8.             newArticle.textContent = articles[index];
  9.             content.insertBefore(newArticle, content.firstChild);
  10.             index++;
  11.         }
  12.     }
  13. }
  14.  
  15.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement