質問編集履歴
9
脱字
test
CHANGED
File without changes
|
test
CHANGED
@@ -56,7 +56,7 @@
|
|
56
56
|
|
57
57
|
Object.defineProperties(B.prototype,
|
58
58
|
|
59
|
-
{instance_a:{set:(value)
|
59
|
+
{instance_a:{set:function(value){this.instance_a.a = value.a}}
|
60
60
|
|
61
61
|
})
|
62
62
|
|
@@ -80,7 +80,7 @@
|
|
80
80
|
|
81
81
|
Object.defineProperties(B.prototype,
|
82
82
|
|
83
|
-
{instance_a:{set:(value)
|
83
|
+
{instance_a:{set:function(value){
|
84
84
|
|
85
85
|
for(var val of Object.getOwnPropertyNames( A.prototype )){
|
86
86
|
|
8
コードを変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,7 +26,7 @@
|
|
26
26
|
|
27
27
|
function B(){
|
28
28
|
|
29
|
-
this.
|
29
|
+
this.attr = new A(1,1,1);
|
30
30
|
|
31
31
|
}
|
32
32
|
|
@@ -84,7 +84,7 @@
|
|
84
84
|
|
85
85
|
for(var val of Object.getOwnPropertyNames( A.prototype )){
|
86
86
|
|
87
|
-
this.
|
87
|
+
this.attr[val] = value[val]
|
88
88
|
|
89
89
|
}
|
90
90
|
|
7
脱字
test
CHANGED
File without changes
|
test
CHANGED
@@ -58,7 +58,7 @@
|
|
58
58
|
|
59
59
|
{instance_a:{set:(value)=>this.instance_a.a = value.a}
|
60
60
|
|
61
|
-
}
|
61
|
+
})
|
62
62
|
|
63
63
|
b.instance_a = a;
|
64
64
|
|
6
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
```javascript
|
6
6
|
|
7
|
-
fuc
|
7
|
+
function A(a,b,c){
|
8
8
|
|
9
9
|
this.a = a;
|
10
10
|
|
@@ -24,7 +24,7 @@
|
|
24
24
|
|
25
25
|
|
26
26
|
|
27
|
-
fuc
|
27
|
+
function B(){
|
28
28
|
|
29
29
|
this.instance_a = new A(1,1,1);
|
30
30
|
|
5
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -106,7 +106,11 @@
|
|
106
106
|
|
107
107
|
|
108
108
|
|
109
|
+
追記
|
110
|
+
|
111
|
+
|
112
|
+
|
109
|
-
|
113
|
+
for文で回したい理由があって実はpropertyのsetter経由で代入を行うと,viewの変更も同時に行うように設定したくて,
|
110
114
|
|
111
115
|
|
112
116
|
|
@@ -126,7 +130,7 @@
|
|
126
130
|
|
127
131
|
}
|
128
132
|
|
129
|
-
Object.defineProperties(B.prototype,properties
|
133
|
+
Object.defineProperties(B.prototype,properties)
|
130
134
|
|
131
135
|
|
132
136
|
|
@@ -136,4 +140,4 @@
|
|
136
140
|
|
137
141
|
としてvalueの条件分岐でViewをupdateするメソッドを作っています。
|
138
142
|
|
139
|
-
なのでObject.getOwnPropertyNames( A.prototype )から余計なpropertiesを弾く方法で実装したいと
|
143
|
+
なのでObject.getOwnPropertyNames( A.prototype )から余計なpropertiesを弾く方法で実装したいという経緯があります。
|
4
補足
test
CHANGED
File without changes
|
test
CHANGED
@@ -100,4 +100,40 @@
|
|
100
100
|
|
101
101
|
,余計なsomeActionなどのインスタンスメソッドやconstructorなどが一緒に取得されてしまいます。これらを排除して,propertyを得るようなメソッドはありますか?
|
102
102
|
|
103
|
+
|
104
|
+
|
103
105
|
なければ全部列挙すれば済むのですが,もしそれより簡単にできる方法をご存知の方や思いつく方がいらっしゃれば教えていただければと思います。宜しくお願いします。
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
追記 for文で回したい理由があって実はpropertyのsetter経由で代入を行うと,viewの変更も同時に行うように設定したくて,
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
```javascript
|
114
|
+
|
115
|
+
properties = {};
|
116
|
+
|
117
|
+
for(var val of Object.getOwnPropertyNames( A.prototype )){
|
118
|
+
|
119
|
+
properties[val] = {set:((val)=>{(value)=>{
|
120
|
+
|
121
|
+
this.instance_a[val] = value;
|
122
|
+
|
123
|
+
updateView(value);
|
124
|
+
|
125
|
+
}})(val)};
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
Object.defineProperties(B.prototype,properties})
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
```
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
としてvalueの条件分岐でViewをupdateするメソッドを作っています。
|
138
|
+
|
139
|
+
なのでObject.getOwnPropertyNames( A.prototype )から余計なpropertiesを弾く方法で実装したいと思っています。
|
3
タイトルの整合性を修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Object.definePropertiesで定義されたproperty
|
1
|
+
Object.definePropertiesでクラス名に定義されたpropertyを自動で設定したい
|
test
CHANGED
File without changes
|
2
誤り訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -56,31 +56,45 @@
|
|
56
56
|
|
57
57
|
Object.defineProperties(B.prototype,
|
58
58
|
|
59
|
-
{a:{set:(value)=>this.instance_a.a = value.a}
|
59
|
+
{instance_a:{set:(value)=>this.instance_a.a = value.a}
|
60
60
|
|
61
61
|
}
|
62
62
|
|
63
|
-
b.a = a
|
63
|
+
b.instance_a = a;
|
64
64
|
|
65
65
|
```
|
66
66
|
|
67
|
-
としてプロパティに設定したクラスのそれぞれのpropertyに
|
67
|
+
としてプロパティに設定したクラスのそれぞれのpropertyに参照渡しではなく
|
68
68
|
|
69
|
-
アクセスできるようにしたいです。
|
69
|
+
コピー代入でアクセスできるようにしたいです。
|
70
|
+
|
71
|
+
|
70
72
|
|
71
73
|
上記のコードでは一つ一つのプロパティに同じように列挙すればできますが,
|
72
74
|
|
73
75
|
プロパティの数が多いので,
|
74
76
|
|
77
|
+
|
78
|
+
|
75
|
-
|
79
|
+
```javascript
|
76
80
|
|
77
81
|
Object.defineProperties(B.prototype,
|
78
82
|
|
79
|
-
{a:{set:(value)=>
|
83
|
+
{instance_a:{set:(value)=>
|
80
84
|
|
81
|
-
|
85
|
+
for(var val of Object.getOwnPropertyNames( A.prototype )){
|
82
86
|
|
87
|
+
this.instance_a[val] = value[val]
|
88
|
+
|
83
|
-
}
|
89
|
+
}
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
})
|
94
|
+
|
95
|
+
```
|
96
|
+
|
97
|
+
|
84
98
|
|
85
99
|
などとしたいのですが
|
86
100
|
|
1
脱字
test
CHANGED
File without changes
|
test
CHANGED
@@ -60,7 +60,7 @@
|
|
60
60
|
|
61
61
|
}
|
62
62
|
|
63
|
-
b.a = a;
|
63
|
+
b.a = a.a;
|
64
64
|
|
65
65
|
```
|
66
66
|
|