File tree Expand file tree Collapse file tree 3 files changed +6
-3
lines changed
_samples/object-mutated-by-function Expand file tree Collapse file tree 3 files changed +6
-3
lines changed Original file line number Diff line number Diff line change 11function incrementAge ( person ) {
22 person . age += 1 ;
3+ return person ;
34}
45
56const tanaka = { name : "田中" , age : 18 } ;
67const nextYearTanaka = incrementAge ( tanaka ) ;
78document . write ( nextYearTanaka . age ) ;
8-
9+ document . write ( " " ) ;
910// 19 と表示されてしまう
1011document . write ( tanaka . age ) ;
Original file line number Diff line number Diff line change @@ -38,6 +38,8 @@ JavaScript において、それはコードを読んだ際に読みやすいか
3838``` javascript
3939const person = { name: " 田中" , age: 18 };
4040person .name = " 佐藤" ; // OK
41+ // 変数自体への再代入はできない
42+ // person = { name: "佐藤", age: 20 };
4143```
4244
4345:::
@@ -101,7 +103,7 @@ function incrementAge(person) {
101103const tanaka = { name: " 田中" , age: 18 };
102104const nextYearTanaka = incrementAge (tanaka);
103105document .write (nextYearTanaka .age );
104-
106+ document . write ( " " );
105107// 19 と表示されてしまう
106108document .write (tanaka .age );
107109```
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ import Answer from "@site/src/components/Answer";
99
1010## <Term type =" javascriptClass " >クラス</Term >と<Term type =" javascriptInstance " >インスタンス</Term >
1111
12- < Term type = " javascriptObject " >オブジェクト</ Term >を使うと 、複数の値をひとまとまりに扱うことができました。実世界においては、同じ<Term type =" javascriptProperty " >プロパティ</Term >(属性)を持つ<Term type =" javascriptObject " >オブジェクト</Term >を多く扱う場合が多いです。例えば、学生を<Term type =" javascriptObject " >オブジェクト</Term >として表すことを考えてみましょう。学生には必ず名前と年齢という属性があるはずなので、ひとまず ` name ` と ` age ` を<Term type="javascriptProperty">プロパティ</Term >に持つとしましょう。
12+ オブジェクトを使うと 、複数の値をひとまとまりに扱うことができました。実世界においては、同じ<Term type =" javascriptProperty " >プロパティ</Term >(属性)を持つ<Term type =" javascriptObject " >オブジェクト</Term >を多く扱う場合が多いです。例えば、学生を<Term type =" javascriptObject " >オブジェクト</Term >として表すことを考えてみましょう。学生には必ず名前と年齢という属性があるはずなので、ひとまず ` name ` と ` age ` を<Term type="javascriptProperty">プロパティ</Term >に持つとしましょう。
1313
1414``` javascript
1515const tanaka = {
You can’t perform that action at this time.
0 commit comments