回答編集履歴

3

調整

2024/07/25 03:32

投稿

yambejp
yambejp

スコア116220

test CHANGED
@@ -11,8 +11,8 @@
11
11
  const test2=new myClass(100);
12
12
  console.log([test1.a,test1.b,test1.c]); //この時点ではb,cは未設定
13
13
  console.log([test2.a,test2.b,test2.c]); //この時点ではcは未設定
14
- myClass.prototype.b=3;
14
+ myClass.prototype.b=2;
15
- myClass.prototype.c=4;
15
+ myClass.prototype.c=3;
16
16
  console.log([test1.a,test1.b,test1.c]); //prototypeを変更する前のインスタンスにも反映されb,cが設定
17
17
  console.log([test2.a,test2.b,test2.c]); //prototypeを変更する前のインスタンスにも反映されcが設定
18
18
  const test3=new myClass;
@@ -20,3 +20,4 @@
20
20
  console.log([test3.a,test3.b,test3.c]); //test1と同値
21
21
  console.log([test4.a,test4.b,test4.c]); //test2と同値
22
22
  ```
23
+ ※ちょっと意図が伝わりづらかったのでコメントをつけておきます

2

調整

2024/07/25 03:30

投稿

yambejp
yambejp

スコア116220

test CHANGED
@@ -9,12 +9,14 @@
9
9
  }
10
10
  const test1=new myClass;
11
11
  const test2=new myClass(100);
12
+ console.log([test1.a,test1.b,test1.c]); //この時点ではb,cは未設定
13
+ console.log([test2.a,test2.b,test2.c]); //この時点ではcは未設定
12
- myClass.prototype.b=2;
14
+ myClass.prototype.b=3;
13
- myClass.prototype.c=3;
15
+ myClass.prototype.c=4;
16
+ console.log([test1.a,test1.b,test1.c]); //prototypeを変更する前のインスタンスにも反映されb,cが設定
17
+ console.log([test2.a,test2.b,test2.c]); //prototypeを変更する前のインスタンスにも反映されcが設定
14
18
  const test3=new myClass;
15
19
  const test4=new myClass(100);
16
- console.log([test1.a,test1.b,test1.c]);
17
- console.log([test2.a,test2.b,test2.c]);
18
- console.log([test3.a,test3.b,test3.c]);
20
+ console.log([test3.a,test3.b,test3.c]); //test1と同値
19
- console.log([test4.a,test4.b,test4.c]);
21
+ console.log([test4.a,test4.b,test4.c]); //test2と同値
20
22
  ```

1

調整

2024/07/25 03:18

投稿

yambejp
yambejp

スコア116220

test CHANGED
@@ -9,8 +9,8 @@
9
9
  }
10
10
  const test1=new myClass;
11
11
  const test2=new myClass(100);
12
- myClass.prototype.b=3;
12
+ myClass.prototype.b=2;
13
- myClass.prototype.c=4;
13
+ myClass.prototype.c=3;
14
14
  const test3=new myClass;
15
15
  const test4=new myClass(100);
16
16
  console.log([test1.a,test1.b,test1.c]);