Comment

Comment by SeanLuke

I'm interested in this simple closure code from the article:

     function getGetNext() {
       let i = 2;
       return function getNext() {
         const next = i;
         i = i * 2;
         return next;
        }
     }
As a lisp coder [and not a JS coder], I'm wondering: why does the function getNext() have to be named? Why not just say something like:

     function getGetNext() {
       let i = 2;
       return function() {
         const next = i;
         i = i * 2;
         return next;
        }
     }
parent SeanLuke 8 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton