Skip to content

incrementAgeの課題に佐藤を追加#537

Merged
na-trium-144 merged 5 commits into
masterfrom
sato-increment-age
Nov 6, 2023
Merged

incrementAgeの課題に佐藤を追加#537
na-trium-144 merged 5 commits into
masterfrom
sato-increment-age

Conversation

@na-trium-144
Copy link
Copy Markdown
Contributor

fix #261

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Nov 4, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7c9fb94
Status: ✅  Deploy successful!
Preview URL: https://382e769e.utcode-learn.pages.dev
Branch Preview URL: https://sato-increment-age.utcode-learn.pages.dev

View logs

@na-trium-144 na-trium-144 requested a review from chvmvd November 4, 2023 07:01
Comment thread docs/1-trial-session/11-object/index.md Outdated

const tanaka = { name: "田中", age: 18 };
const tanaka = { name: "田中", age: 18 },
sato = { name: "佐藤", age: 22 };
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

,区切りで複数の宣言ができることを教材で教えていないので、それぞれ分けて宣言していただけるとありがたいです。

Copy link
Copy Markdown
Contributor

@aster-void aster-void Nov 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

というか多分これだと sato がグローバルスコープになるので好ましくないです

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これはもともとtanakaもグローバルスコープじゃないんですか?

Copy link
Copy Markdown
Contributor

@aster-void aster-void Nov 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この場合はそうなんですけど、const a = 1, b = 2 のようにすると const a = 1b = 2 という2つの文(式)として解釈されるので、他の関数などの中に入れたとしても b (sato) はグローバルスコープになってしまいます。
cf.
https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Comma_operator

https://www.codegrid.net/articles/2017-js-scope-1/#toc-5

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

訂正: 今試したところ、カンマ区切りはいい感じに解釈してくれるみたいです。
const a = b = 1; と間違えてました

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

constもletもvarもカンマ区切りで複数の変数を宣言できるはずです
https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Statements/const

それはそれとしてあとで2文にわけておきます

Comment thread docs/1-trial-session/11-object/index.md Outdated

const tanaka = { name: "田中", age: 18 };
const tanaka = { name: "田中", age: 18 },
sato = { name: "佐藤", age: 22 };
Copy link
Copy Markdown
Contributor

@aster-void aster-void Nov 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

というか多分これだと sato がグローバルスコープになるので好ましくないです

Comment thread docs/1-trial-session/11-object/index.md Outdated
sato = { name: "佐藤", age: 22 };
const nextYearTanaka = incrementAge(tanaka);
document.write(nextYearTanaka.age); // 19 と表示されてほしい
const nextYearSato = incrementAge(sato); // 同じ関数を tanaka と sato に使い回せる
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この説明は関数のところでしてるので必要ないのでは?

@na-trium-144 na-trium-144 requested a review from chvmvd November 6, 2023 12:12
@na-trium-144
Copy link
Copy Markdown
Contributor Author

レビューで指摘された箇所はたぶん直しました。

Copy link
Copy Markdown
Contributor

@chvmvd chvmvd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます!

@na-trium-144 na-trium-144 merged commit f6f3344 into master Nov 6, 2023
@na-trium-144 na-trium-144 deleted the sato-increment-age branch November 6, 2023 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

オブジェクトの課題で関数化している意義がわかりにくい。

3 participants