Skip to Content
Head First JavaScriptプログラミング、第2版
book

Head First JavaScriptプログラミング、第2版

by Eric Freeman, Elisabeth Robson
March 2025
Intermediate to advanced
662 pages
13h 28m
Japanese
O'Reilly Media, Inc.
Content preview from Head First JavaScriptプログラミング、第2版

付録A. 残り物:トップ10のトピック(カバーしていない)

Image

私たちは多くの分野をカバーし、あなたはこの本をほぼ読み終えた。寂しくなるが、君たちを手放す前に、もう少しの準備なしに君たちを社会に送り出すのは気が引ける。この比較的小さな章に、君たちが知るべきことをすべて盛り込むことはできない。実は、もともとJavaScriptプログラミングについて知っておく必要があること(他の章ですでにカバーされていないこと)は、活字のポイントサイズを0.00004に小さくすることですべて盛り込んだ。しかし、誰もそれを読み取ることができなかった。そこで、そのほとんどを捨て、この「トップ10」付録Aのために最良の部分を残した。

これで本当にこの本は終わりだ。もちろん索引は別だ(必読!)。

#1 モジュール

この本では、スコープについてたくさん話をした。スコープに関連するJavaScript言語の機能で、触れなかったものにモジュールがある。モジュールは、ファイル・レベルでコードの可視性を制限するもうひとつの方法だ。

モジュールを使うのは簡単だ。つの新しいキーワードといくつかの簡単な規則を覚えるだけでいい。例えば、"taxi.js "というファイルがあって、その中にタクシーの車両を作成するクラスTaxi と関数createFleet があるとする。また、タクシーを呼びたいユーザのために、タクシーのリストを作成するWebページがあるとする。

HTMLから "taxi.js "ファイルへのリンクは、通常のスクリプト・リンクを使うことができる:

<script src="./taxi.js"></script>
<script>
  // code to create and list a fleet of taxis
</script>

しかし、みんなにcreateFleet を呼び出してほしいが、タクシーを直接インスタンス化してほしくない。モジュールを使えば、export キーワードを使って、「taxi.js」ファイルから何がエクスポートされるかをコントロールできる。Taxi クラスとcreateFleet 関数を含む「taxi.js」ファイルを見てみよう:

Image

モジュールを使うには、それを使いたいJavaScriptにインポートしなければならない。例えば、"taxi.html "というWebページがあり、そこにタクシーを表示するとしよう。今までのように(そして前のページで示したように)「taxi.js」ファイルにリンクするのではなく、次のようにJavaScriptで importキーワードを使用する:

Image

taxi.html "ファイル内のコードは、Taxi クラスにアクセスできないことに注意してほしい。なぜなら、このクラスは "taxi.js "モジュールからエクスポートされたものでも、"taxi.html ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

技術リーダーシップのための14のヒント

技術リーダーシップのための14のヒント

島田 浩二
カオスエンジニアリング ―回復力のあるシステムの実践

カオスエンジニアリング ―回復力のあるシステムの実践

Casey Rosenthal, Nora Jones, 堀 明子, 松浦 隼人
Tidy First? ―個人で実践する経験主義的ソフトウェア設計

Tidy First? ―個人で実践する経験主義的ソフトウェア設計

Kent Beck, 吉羽 龍太郎, 永瀬 美穂, 細澤 あゆみ

Publisher Resources

ISBN: 9798341633186