Conversation
bf5fed0 to
1153079
Compare
Deploying utcode-learn with
|
| Latest commit: |
5066c13
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://b6200e1c.utcode-learn.pages.dev |
| Branch Preview URL: | https://rewrite-variable-scope.utcode-learn.pages.dev |
1153079 to
1c4b02e
Compare
|
|
||
| function greet() { | ||
| guestCount += 1; | ||
| guestCount = guestCount + 1; |
There was a problem hiding this comment.
ここで初出の += が出てくるとノイズなので、ここでは普通に今まで扱った方法で書き、下のコラム内で「これを += に書き換えられる」という説明をするようにしています
|
|
||
| greet(); | ||
|
|
||
| // document.write(message); これはエラーになる |
There was a problem hiding this comment.
エラーになるサンプルコードを提供しない、という方針に従いコメントアウトしている
There was a problem hiding this comment.
Pull request overview
「変数のスコープ」セクションを、具体例(関数内のローカル変数/外側で宣言した変数の参照)を用いて説明し直し、合わせて複合代入演算子の説明導線を整理するPRです。
Changes:
- スコープの説明を、
messageのローカルスコープ例(関数内のみ参照可)で具体化 - 外側(関数外)で宣言した変数を関数内から参照・更新できる例を維持しつつ、説明文をリライト
- 複合代入演算子の説明を「
guestCount = guestCount + 1→guestCount += 1」の流れに整理
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
3ee392d to
a5ef48a
Compare
|
|
||
| ```javascript | ||
| function greet() { | ||
| let message = "Hello!"; |
There was a problem hiding this comment.
ここでconstではなく、letを使った理由が分からなかったのですが、何かあったりしますか?
There was a problem hiding this comment.
あー普通に忘れてました・・
ただ、下で関数外の変数を参照する例は let でこちらが const なのはノイズなのでどちらかに統一しようとは思います
まあ両方 const にして、+= の話は全部複合代入演算子のコラム内でやるようにしようかなぁ
There was a problem hiding this comment.
こちらがconstで、下の例がletになってしまってもそんなに問題ないとは私は思いますが。いい例があれば、そのように統一しても良いと思います。
|
|
||
| ```javascript | ||
| function greet() { | ||
| let message = "Hello!"; |
There was a problem hiding this comment.
(optional)
上の説明では、メッセージが"Hello!"ではなく、"Hello World!"になっているため、そちらに統一すると認知負荷が少し小さくなるかもしれません。
utcode-learn/docs/1-trial-session/09-functions/index.mdx
Lines 11 to 20 in 27d5138
|
|
||
| ```javascript | ||
| function greet() { | ||
| let message = "Hello!"; |
|
|
||
| greet(); | ||
|
|
||
| // document.write(message); これはエラーになる |
There was a problem hiding this comment.
(optional)
これを単にコメントアウトすると、document.write(message); これはエラーになるとなってしまい、これも構文エラーになってしまうため、単にコメントアウトしても構文エラーにならないようになっていると少し親切かもしれません。
There was a problem hiding this comment.
個人的には次のようにエラーとなるところをコメントアウトせずに書くというのも悪くない気もしてきましたが。
utcode-learn/docs/4-advanced/03-typescript/index.mdx
Lines 102 to 104 in c8ad394
https://github.com/mdn/translated-content/blob/7fa1e352b7db8747d8f1050c1d5c4444343047a0/files/ja/web/javascript/guide/grammar_and_types/index.md?plain=1#L132-L135
There was a problem hiding this comment.
あー別にエラーになるコードを書いちゃってる例もあるんですね
ならそれが一番わかりやすそう
(ただまあ今回のはランタイムエラーだし議論の余地はありそう?)
nakaterm
left a comment
There was a problem hiding this comment.
すみません、全体的に例を変えました!
|
|
||
| ```javascript | ||
| guestCount = guestCount + 1; | ||
| const siteName = "田中のブログ"; |
There was a problem hiding this comment.
この節の上の例で使われている greetingType や myName にあたるものを使うことも考えたのですが、そうすると同じユースケースで上では引数で渡しており、こちらでは渡していないということになって混乱を招くので例を変えました。
定数としておいていても変ではないものを探した結果、siteName にしました。
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
一応 |
resolves #815