質問編集履歴
2
setterの部分を修正[未定義のPropertyの場合、処理しない様に修正]
test
CHANGED
File without changes
|
test
CHANGED
@@ -126,158 +126,352 @@
|
|
126
126
|
|
127
127
|
```javascriot
|
128
128
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
//
|
134
|
-
|
135
|
-
var
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
var
|
140
|
-
|
141
|
-
|
129
|
+
(function () {
|
130
|
+
|
131
|
+
// 基底セッター
|
132
|
+
|
133
|
+
Object.prototype.setter = function(member, /*...multilayered, */value) {// -> member, multilayered, valueは実質使用しない....残余引数で対応したい
|
134
|
+
|
135
|
+
var obj = this;// -> Class化されたオブジェクトに対応
|
136
|
+
|
137
|
+
// 通常配列化
|
138
|
+
|
139
|
+
var _args = Array.from(arguments); // -> ポリフィルを作成した(IEとか対応)
|
140
|
+
|
141
|
+
if (_args.length < 2) {
|
142
|
+
|
143
|
+
var msg = 'Unexpected execution: there are not enough arguments to execute ' + typeof this + '.';
|
144
|
+
|
145
|
+
throw new TypeError(msg);
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
var changeAssignValue = _args.pop(); // -> _argsから最後の要素を削除し、変数[changeAssignValue]でキャッチする
|
150
|
+
|
151
|
+
var menberKeyList = getMenberKeyList(_args.flat(1/0)); //-> _argsの中身を単配列化&階層を配列に詰める
|
152
|
+
|
153
|
+
var menberLayeredLength = menberKeyList.length;
|
154
|
+
|
155
|
+
var menberListIndex = 0;
|
156
|
+
|
157
|
+
var hasMenber = false;
|
158
|
+
|
159
|
+
var memberName = void(0);
|
160
|
+
|
161
|
+
var _obj = obj; // -> 処理用変数
|
162
|
+
|
163
|
+
var isLast = false;
|
164
|
+
|
165
|
+
while (menberListIndex < menberLayeredLength) {
|
166
|
+
|
167
|
+
isLast = (menberListIndex == menberLayeredLength - 1);
|
168
|
+
|
169
|
+
memberName = menberKeyList[menberListIndex];
|
170
|
+
|
171
|
+
hasMenber = _obj.hasOwnProperty(memberName); // -> objではダメ。。1階層目以外書き換え不可
|
172
|
+
|
173
|
+
if (hasMenber) {
|
174
|
+
|
175
|
+
// 最後のindexのみ、propertyの書き換え
|
176
|
+
|
177
|
+
if (isLast) {
|
178
|
+
|
179
|
+
Object.defineProperty(_obj, memberName, { value: changeAssignValue, writable: false, enumerable: true });
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
_obj = _obj[memberName];
|
184
|
+
|
185
|
+
} else {
|
186
|
+
|
187
|
+
//_obj[memberName] = {};// -> 不用意なメンバー追加は避けた方が良いかも。。。
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
menberListIndex++;
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
return obj;
|
196
|
+
|
197
|
+
};
|
198
|
+
|
199
|
+
// 念のため、列挙不可へ書き換え...jQueryUIの処理とバッティングする
|
200
|
+
|
201
|
+
Object.defineProperty(Object.prototype, 'setter', { value: Object.prototype.setter, writable: false, enumerable: false });
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
// 基底ゲッター
|
206
|
+
|
207
|
+
Object.prototype.getter = function(member/*, ...multilayered*/){// -> m, multilayeredは実質使用しない....残余引数で対応
|
208
|
+
|
209
|
+
var obj = this;// -> Class化されたオブジェクトに対応
|
210
|
+
|
211
|
+
// 通常配列化
|
212
|
+
|
213
|
+
var _args = Array.from(arguments); // -> ポリフィルを作成した(IEとか対応)
|
214
|
+
|
215
|
+
if (_args.length < 1) {
|
216
|
+
|
217
|
+
var msg = 'Unexpected execution: there are not enough arguments to execute ' + typeof this + '.';
|
218
|
+
|
219
|
+
throw new TypeError(msg);
|
220
|
+
|
221
|
+
}
|
222
|
+
|
223
|
+
var results = null;
|
224
|
+
|
225
|
+
var menberKeyList = getMenberKeyList(_args.flat(1/0)); //-> _argsの中身を単配列化&階層を配列に詰める
|
226
|
+
|
227
|
+
var menberLayeredLength = menberKeyList.length;
|
228
|
+
|
229
|
+
var menberListIndex = 0;
|
230
|
+
|
231
|
+
var hasMenber = false;
|
232
|
+
|
233
|
+
var memberName = void(0);
|
234
|
+
|
235
|
+
var _obj = obj; // -> 処理用変数
|
236
|
+
|
237
|
+
while (menberListIndex < menberLayeredLength) {
|
238
|
+
|
239
|
+
isLast = (menberListIndex == menberLayeredLength - 1);
|
240
|
+
|
241
|
+
memberName = menberKeyList[menberListIndex];
|
242
|
+
|
243
|
+
hasMenber = _obj.hasOwnProperty(memberName); // -> objではダメ。。1階層目以外書き換え不可
|
244
|
+
|
245
|
+
if (hasMenber) {
|
246
|
+
|
247
|
+
if (isLast) {
|
248
|
+
|
249
|
+
results = _obj[memberName];
|
250
|
+
|
251
|
+
}
|
252
|
+
|
253
|
+
_obj = _obj[memberName];
|
254
|
+
|
255
|
+
}
|
256
|
+
|
257
|
+
menberListIndex++;
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
return results;
|
262
|
+
|
263
|
+
};
|
264
|
+
|
265
|
+
// 念のため、列挙不可へ書き換え...jQueryUIの処理とバッティングする
|
266
|
+
|
267
|
+
Object.defineProperty(Object.prototype, 'getter', { value: Object.prototype.getter, writable: false, enumerable: false });
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
// Array[ポリフィル:IE11対応]
|
272
|
+
|
273
|
+
Object.defineProperty(Array.prototype, 'flat', { writable: false, enumerable: false, value: (function (){
|
274
|
+
|
275
|
+
return (Array.prototype.flat) ? Array.prototype.flat : function (deepth) {
|
276
|
+
|
277
|
+
var _arr = this;
|
278
|
+
|
279
|
+
if (isNaN(deepth)) { deepth = 1; }
|
280
|
+
|
281
|
+
return deepth > 0 ? _arr.reduce(function (acc, val) {
|
282
|
+
|
283
|
+
return acc.concat(Array.isArray(val) ? val.flatDeep(deepth - 1) : val);
|
284
|
+
|
285
|
+
}, []) : _arr.slice();
|
286
|
+
|
287
|
+
};
|
288
|
+
|
289
|
+
})()});
|
290
|
+
|
291
|
+
Object.defineProperty(Array, 'from', { writable: false, enumerable: false, value: (function () {
|
292
|
+
|
293
|
+
return (Array.from) ? Array.from : function (arrayLike/*, mapFn, thisArg */) {
|
294
|
+
|
295
|
+
var arr = this;
|
296
|
+
|
297
|
+
var items = Object(arrayLike);
|
298
|
+
|
299
|
+
if (arrayLike == null) {
|
300
|
+
|
301
|
+
throw new TypeError('Array.from requires an array-like object - not null or undefined');
|
302
|
+
|
303
|
+
}
|
304
|
+
|
305
|
+
var mapFn = arguments.length > 1 ? arguments[1] : void undefined;// -> 受け取った場合はそれを使う
|
306
|
+
|
307
|
+
var _this;
|
308
|
+
|
309
|
+
if (typeof mapFn !== 'undefined') {
|
310
|
+
|
311
|
+
if (!isCallable(mapFn)) {
|
312
|
+
|
313
|
+
throw new TypeError('Array.from: when provided, the second argument must be a function');
|
314
|
+
|
315
|
+
}
|
316
|
+
|
317
|
+
if (arguments.length > 2) {
|
318
|
+
|
319
|
+
_this = arguments[2];
|
320
|
+
|
321
|
+
}
|
322
|
+
|
323
|
+
}
|
324
|
+
|
325
|
+
var len = toLength(items.length);
|
326
|
+
|
327
|
+
var Arr = isCallable(arr) ? Object(new arr(len)) : new Array(len);
|
328
|
+
|
329
|
+
var index = 0;
|
330
|
+
|
331
|
+
var item;
|
332
|
+
|
333
|
+
while (index < len) {
|
334
|
+
|
335
|
+
item = items[index];
|
336
|
+
|
337
|
+
if (mapFn) {
|
338
|
+
|
339
|
+
Arr[index] = typeof _this === 'undefined' ? mapFn(item, index) : mapFn.call(_this, item, index);
|
340
|
+
|
341
|
+
} else {
|
342
|
+
|
343
|
+
Arr[index] = item;
|
344
|
+
|
345
|
+
}
|
346
|
+
|
347
|
+
index += 1;
|
348
|
+
|
349
|
+
}
|
350
|
+
|
351
|
+
Arr.length = len;
|
352
|
+
|
353
|
+
return Arr;
|
354
|
+
|
355
|
+
};
|
356
|
+
|
357
|
+
// 秘匿関数
|
358
|
+
|
359
|
+
function isCallable (fn) {
|
360
|
+
|
361
|
+
return typeof fn === 'function' || Object.prototype.toString.call(fn) === '[object Function]';
|
362
|
+
|
363
|
+
}
|
364
|
+
|
365
|
+
function toInteger (value) {
|
366
|
+
|
367
|
+
var number = Number(value);
|
368
|
+
|
369
|
+
if (isNaN(number)) {
|
370
|
+
|
371
|
+
return 0;
|
372
|
+
|
373
|
+
}
|
374
|
+
|
375
|
+
if (number === 0 || !isFinite(number)) {
|
376
|
+
|
377
|
+
return number;
|
378
|
+
|
379
|
+
}
|
380
|
+
|
381
|
+
return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number));
|
382
|
+
|
383
|
+
}
|
384
|
+
|
385
|
+
function toLength (value) {
|
386
|
+
|
387
|
+
var maxSafeInteger = Math.pow(2, 53) - 1; // 2^53-1 約9千兆
|
388
|
+
|
389
|
+
var len = toInteger(value);
|
390
|
+
|
391
|
+
return Math.min(Math.max(len, 0), maxSafeInteger);
|
392
|
+
|
393
|
+
};
|
394
|
+
|
395
|
+
})()});
|
396
|
+
|
397
|
+
|
398
|
+
|
399
|
+
/** 秘匿関数 */
|
400
|
+
|
401
|
+
// 階層を順番に並び替えて返却(単配列化)
|
402
|
+
|
403
|
+
function getMenberKeyList (obj) {
|
404
|
+
|
405
|
+
return (!Array.isArray(obj) || obj.length < 1) ? [] : (function (r, o) {
|
406
|
+
|
407
|
+
var i = 0;
|
408
|
+
|
409
|
+
while (i < o.length) {
|
410
|
+
|
411
|
+
var k = o[i];
|
412
|
+
|
413
|
+
if (Array.isArray(k)) { k = k.flat(1/0).join('.'); }
|
414
|
+
|
415
|
+
if (typeof k != 'string') { k = k.toString(); }
|
416
|
+
|
417
|
+
k = k.split('.');
|
418
|
+
|
419
|
+
r = r.concat(k);
|
420
|
+
|
421
|
+
i++;
|
422
|
+
|
423
|
+
}
|
424
|
+
|
425
|
+
return r;
|
426
|
+
|
427
|
+
})([], obj);
|
142
428
|
|
143
429
|
}
|
144
430
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
var
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
var
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
return _obj;
|
192
|
-
|
193
|
-
// 階層を順番に並び替えて返却(単配列化)
|
194
|
-
|
195
|
-
function getMenberKeyList (obj) {
|
196
|
-
|
197
|
-
return (!Array.isArray(obj) || obj.length < 1) ? [] : (function (r, o) {
|
198
|
-
|
199
|
-
var i = 0;
|
200
|
-
|
201
|
-
while (i < o.length) {
|
202
|
-
|
203
|
-
var k = o[i];
|
204
|
-
|
205
|
-
if (Array.isArray(k)) { k = k.flat(1/0).join('.'); }
|
206
|
-
|
207
|
-
if (typeof k != 'string') { k = k.toString(); }
|
208
|
-
|
209
|
-
k = k.split('.');
|
210
|
-
|
211
|
-
r = r.concat(k);
|
212
|
-
|
213
|
-
i++;
|
214
|
-
|
215
|
-
}
|
216
|
-
|
217
|
-
return r;
|
218
|
-
|
219
|
-
})([], obj);
|
220
|
-
|
221
|
-
}
|
222
|
-
|
223
|
-
};
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
// -> test code type Array
|
228
|
-
|
229
|
-
var nestedArray = [[[[[[1,2,3]]]]]];
|
230
|
-
|
231
|
-
console.log(nestedArray); // -> [0: [0: [0: [0: [0: [0: 1. 1: 2, 2: 3]]]]]];
|
232
|
-
|
233
|
-
nestedArray.setter('0.0.0.0.0.1',5);
|
234
|
-
|
235
|
-
console.log(nestedArray); // -> [0: [0: [0: [0: [0: [0: 1. 1: 5, 2: 3]]]]]];
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
// -> test code type Object
|
240
|
-
|
241
|
-
var nestedObject = {a: {b: {c: {d: {e: 'hoge', z: 'fuga'}}}}};
|
242
|
-
|
243
|
-
console.log(nestedObject); // -> {a: {b: {c: {d: {e: 'hoge', z: 'fuga'}}}}};
|
244
|
-
|
245
|
-
nestedObject.setter('a.b','c',['d','e'],'hogehoge');
|
246
|
-
|
247
|
-
console.log(nestedObject); // -> {a: {b: {c: {d: {e: 'hogehoge', z: 'fuga'}}}}};
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
// -> test code type Instance
|
252
|
-
|
253
|
-
var _func = function _func () {
|
254
|
-
|
255
|
-
this.mem1 = {};
|
256
|
-
|
257
|
-
this.mem1.mem2 = {};
|
258
|
-
|
259
|
-
this.mem1.mem2.mem3 = {};
|
260
|
-
|
261
|
-
this.mem1.mem2.mem3.mem4 = {};
|
262
|
-
|
263
|
-
this.mem1.mem2.mem3.mem4.mem5 = 'member5';
|
264
|
-
|
265
|
-
this.mem1.mem2.mem3.mem4.mem6 = 'member6';
|
266
|
-
|
267
|
-
}
|
268
|
-
|
269
|
-
var nestedPropIns = new _func();
|
270
|
-
|
271
|
-
console.log(nestedPropIns); // -> _func: {mem1: {mem2: {mem3: {mem4: {mem5: 'member5', mem6: 'member6'}}}}};
|
272
|
-
|
273
|
-
nestedPropIns.setter('mem1.mem2.mem3.mem4.mem5', '12345');
|
274
|
-
|
275
|
-
console.log(nestedPropIns); // -> _func: {mem1: {mem2: {mem3: {mem4: {mem5: '12345', mem6: 'member6'}}}}};
|
276
|
-
|
277
|
-
nestedPropIns.setter('mem1.mem2.mem3.mem4.mem6', '12346');
|
278
|
-
|
279
|
-
console.log(nestedPropIns); // -> _func: {mem1: {mem2: {mem3: {mem4: {mem5: '12345', mem6: '12346'}}}}};
|
280
|
-
|
281
|
-
|
431
|
+
/** under test code */
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
// -> test code setter by type Array.
|
436
|
+
|
437
|
+
var nestedArray = [[[[[[1,2,3]]]]]];
|
438
|
+
|
439
|
+
console.log(nestedArray.setter('0.0.0.0.0.1',5)); // -> [0: [0: [0: [0: [0: [0: 1. 1: 5, 2: 3]]]]]];
|
440
|
+
|
441
|
+
// -> test code setter by type Object.
|
442
|
+
|
443
|
+
var nestedObject = {a: {b: {c: {d: {e: 'hoge', z: 'fuga'}}}}};
|
444
|
+
|
445
|
+
console.log(nestedObject.setter('a.b','c',['d','e'],'hogehoge')); // -> {a: {b: {c: {d: {e: 'hogehoge', z: 'fuga'}}}}};
|
446
|
+
|
447
|
+
// -> test code setter by type Instance.
|
448
|
+
|
449
|
+
var _func = function _func () { this.mem1 = {mem2: {mem3: {mem4: {mem5: 'member5', mem6: 'member6'}}}}; };
|
450
|
+
|
451
|
+
var nestedPropIns = new _func();
|
452
|
+
|
453
|
+
console.log(nestedPropIns.setter('mem1.mem2.mem3.mem4.mem5', '12345')); // -> _func: {mem1: {mem2: {mem3: {mem4: {mem5: '12345', mem6: 'member6'}}}}};
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
// -> test code getter by type Array.
|
458
|
+
|
459
|
+
console.log(nestedArray.getter('0.0.0.0.0.1'));// -> 5
|
460
|
+
|
461
|
+
console.log(nestedArray.getter('0.0.0.0.0.4'));// -> null
|
462
|
+
|
463
|
+
// -> test code getter by type Object.
|
464
|
+
|
465
|
+
console.log(nestedObject.getter('a.b','c',['d','e'])); // -> hogehoge
|
466
|
+
|
467
|
+
console.log(nestedObject.getter('a.b','c',['d','j'])); // -> null
|
468
|
+
|
469
|
+
// -> test code getter by type Instance.
|
470
|
+
|
471
|
+
console.log(nestedPropIns.getter('mem1.mem2.mem3.mem4.mem5')); // -> 12345
|
472
|
+
|
473
|
+
console.log(nestedPropIns.getter('mem1.mem2.mem3.mem5.mem5')); // -> null
|
474
|
+
|
475
|
+
})();
|
282
476
|
|
283
477
|
```
|
1
最終コードを投稿
test
CHANGED
File without changes
|
test
CHANGED
@@ -119,3 +119,165 @@
|
|
119
119
|
})()
|
120
120
|
|
121
121
|
```
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
### 最終的に出来上がったソースコード
|
126
|
+
|
127
|
+
```javascriot
|
128
|
+
|
129
|
+
Object.prototype.setter = function(member, /*...multilayered, */value) {// -> member, multilayered, vは実質使用しない....残余引数で対応したい
|
130
|
+
|
131
|
+
var _obj = this;// -> Class化されたオブジェクトに対応
|
132
|
+
|
133
|
+
// 通常配列化
|
134
|
+
|
135
|
+
var _args = Array.from(arguments); // -> ポリフィルを作成した(IEとか対応)
|
136
|
+
|
137
|
+
if (_args.length < 2) {
|
138
|
+
|
139
|
+
var msg = 'Unexpected execution: there are not enough arguments to execute ' + typeof this + '.';
|
140
|
+
|
141
|
+
throw new UserException(msg, 'error'); // -> typeは列挙型にしたい
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
var changeAssignValue = _args.pop(); // -> _argsから最後の要素を削除し、変数[changeAssignValue]でキャッチする
|
146
|
+
|
147
|
+
var menberKeyList = getMenberKeyList(_args.flat(1/0)); //-> _argsの中身を単配列化&階層を配列に詰める
|
148
|
+
|
149
|
+
var menberLayeredLength = menberKeyList.length;
|
150
|
+
|
151
|
+
var menberListIndex = 0;
|
152
|
+
|
153
|
+
var hasMenber = false;
|
154
|
+
|
155
|
+
var memberName = void(0);
|
156
|
+
|
157
|
+
var o = _obj; // -> 処理用変数
|
158
|
+
|
159
|
+
var isLast = false;
|
160
|
+
|
161
|
+
while (menberListIndex < menberLayeredLength) {
|
162
|
+
|
163
|
+
isLast = (menberListIndex == menberLayeredLength - 1);
|
164
|
+
|
165
|
+
memberName = menberKeyList[menberListIndex];
|
166
|
+
|
167
|
+
hasMenber = o.hasOwnProperty(memberName); // -> _objではダメ。。1階層目以外書き換え不可
|
168
|
+
|
169
|
+
if (hasMenber) {
|
170
|
+
|
171
|
+
// 最後のindexのみ、propertyの書き換え
|
172
|
+
|
173
|
+
if (isLast) {
|
174
|
+
|
175
|
+
Object.defineProperty(o, memberName, { value: changeAssignValue, writable: false, enumerable: true });
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
} else {
|
180
|
+
|
181
|
+
o[memberName] = {};// -> 不用意なメンバー追加は避けた方が良いかも。。。
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
o = o[memberName];
|
186
|
+
|
187
|
+
menberListIndex++;
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
return _obj;
|
192
|
+
|
193
|
+
// 階層を順番に並び替えて返却(単配列化)
|
194
|
+
|
195
|
+
function getMenberKeyList (obj) {
|
196
|
+
|
197
|
+
return (!Array.isArray(obj) || obj.length < 1) ? [] : (function (r, o) {
|
198
|
+
|
199
|
+
var i = 0;
|
200
|
+
|
201
|
+
while (i < o.length) {
|
202
|
+
|
203
|
+
var k = o[i];
|
204
|
+
|
205
|
+
if (Array.isArray(k)) { k = k.flat(1/0).join('.'); }
|
206
|
+
|
207
|
+
if (typeof k != 'string') { k = k.toString(); }
|
208
|
+
|
209
|
+
k = k.split('.');
|
210
|
+
|
211
|
+
r = r.concat(k);
|
212
|
+
|
213
|
+
i++;
|
214
|
+
|
215
|
+
}
|
216
|
+
|
217
|
+
return r;
|
218
|
+
|
219
|
+
})([], obj);
|
220
|
+
|
221
|
+
}
|
222
|
+
|
223
|
+
};
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
// -> test code type Array
|
228
|
+
|
229
|
+
var nestedArray = [[[[[[1,2,3]]]]]];
|
230
|
+
|
231
|
+
console.log(nestedArray); // -> [0: [0: [0: [0: [0: [0: 1. 1: 2, 2: 3]]]]]];
|
232
|
+
|
233
|
+
nestedArray.setter('0.0.0.0.0.1',5);
|
234
|
+
|
235
|
+
console.log(nestedArray); // -> [0: [0: [0: [0: [0: [0: 1. 1: 5, 2: 3]]]]]];
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
// -> test code type Object
|
240
|
+
|
241
|
+
var nestedObject = {a: {b: {c: {d: {e: 'hoge', z: 'fuga'}}}}};
|
242
|
+
|
243
|
+
console.log(nestedObject); // -> {a: {b: {c: {d: {e: 'hoge', z: 'fuga'}}}}};
|
244
|
+
|
245
|
+
nestedObject.setter('a.b','c',['d','e'],'hogehoge');
|
246
|
+
|
247
|
+
console.log(nestedObject); // -> {a: {b: {c: {d: {e: 'hogehoge', z: 'fuga'}}}}};
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
// -> test code type Instance
|
252
|
+
|
253
|
+
var _func = function _func () {
|
254
|
+
|
255
|
+
this.mem1 = {};
|
256
|
+
|
257
|
+
this.mem1.mem2 = {};
|
258
|
+
|
259
|
+
this.mem1.mem2.mem3 = {};
|
260
|
+
|
261
|
+
this.mem1.mem2.mem3.mem4 = {};
|
262
|
+
|
263
|
+
this.mem1.mem2.mem3.mem4.mem5 = 'member5';
|
264
|
+
|
265
|
+
this.mem1.mem2.mem3.mem4.mem6 = 'member6';
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
var nestedPropIns = new _func();
|
270
|
+
|
271
|
+
console.log(nestedPropIns); // -> _func: {mem1: {mem2: {mem3: {mem4: {mem5: 'member5', mem6: 'member6'}}}}};
|
272
|
+
|
273
|
+
nestedPropIns.setter('mem1.mem2.mem3.mem4.mem5', '12345');
|
274
|
+
|
275
|
+
console.log(nestedPropIns); // -> _func: {mem1: {mem2: {mem3: {mem4: {mem5: '12345', mem6: 'member6'}}}}};
|
276
|
+
|
277
|
+
nestedPropIns.setter('mem1.mem2.mem3.mem4.mem6', '12346');
|
278
|
+
|
279
|
+
console.log(nestedPropIns); // -> _func: {mem1: {mem2: {mem3: {mem4: {mem5: '12345', mem6: '12346'}}}}};
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
```
|