Home >Web Front-end >JS Tutorial >Detailed explanation of classic js closure

Detailed explanation of classic js closure

零下一度
零下一度Original
2017-07-20 17:12:061631browse

When I re-read js closure, I saw "Classic JS Closure Interview Questions Most People Do Wrong", and I understood and recorded my thoughts. Many bloggers have already explained it in detail, but the explanation behind it is a bit convoluted.

Post the code first

                fun:                   a = fun(0 a.fun(1 a.fun(2 a.fun(3   b=fun(0).fun(1).fun(2).fun(3  c= fun(0).fun(1 c.fun(2 c.fun(3);

Question: What is each output?

Answer:

undefined,0,0,0undefined,0,1,2undefined,0,1,1

Let’s break it down step by step:

The above is the detailed content of Detailed explanation of classic js closure. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:js case marquee codeNext article:js case marquee code