29
25

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JSに=は不要

Last updated at Posted at 2016-06-16

代入文がなくなってJavaScriptは書けるもん。

(function(foo){
    foo();
})(function(){
    (function(x){
        (function(bar){
            bar();
            print(x + x);
        })(function(){
            (function(x){
                print(x + x);
            })(1);
        });
    })(10);
});

ふざけた外観をしてるけれど、このコードは静的スコープによって説明できる。

元ねたは@esehara変数のスコープを意識することについて、Lisp周辺とClojureのletを利用して考える - Line 1: Error: Invalid Blog('by Esehara' )。素晴らしい記事なので、みなさん読むべき。

練習問題

代入文を使った式を=なしの形式に変換してみよう。

あとがき

このコードを理解できれば、一部のプログラミング言語に存在するlet式1をマスターできたと友達に自慢できるぞ。(ES2015の仕様書をちゃんと読んでないんだけど、おそらくJavaScriptのletとは他人の空似)

脚注

  1. Lisp, ML, Haskellなどに存在します

29
25
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
29
25

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?