回答編集履歴

2

配列 -> Array#length / markdown修正

2019/05/14 13:48

投稿

think49
think49

スコア18166

test CHANGED
@@ -230,13 +230,13 @@
230
230
 
231
231
 
232
232
 
233
- 配列がsetterのような挙動を示すのは、配列が**Exotic Objects**として内部メソッド `[[DefineOwnProperty]]` を書き換えている為です。
233
+ `Array#length` がsetterのような挙動を示すのは、配列が**Exotic Objects**として内部メソッド `[[DefineOwnProperty]]` を書き換えている為です。
234
234
 
235
235
 
236
236
 
237
237
  - [9.4.2 Array Exotic Objects - ECMAScript® 2018 Language Specification](http://www.ecma-international.org/ecma-262/9.0/#sec-array-exotic-objects)
238
238
 
239
- - [9.4.2.1 [[DefineOwnProperty]] - ECMAScript® 2018 Language Specification](http://www.ecma-international.org/ecma-262/9.0/#sec-array-exotic-objects)
239
+ - [9.4.2.1 DefineOwnProperty - ECMAScript® 2018 Language Specification](http://www.ecma-international.org/ecma-262/9.0/#sec-array-exotic-objects)
240
240
 
241
241
 
242
242
 
@@ -254,7 +254,7 @@
254
254
 
255
255
 
256
256
 
257
- 配列はgetterでもありませんので、「要素数が確定するタイミング」は jQuery#length と基本的に同じです。
257
+ `Array#length` はgetterでもありませんので、「要素数が確定するタイミング」は jQuery#length と基本的に同じです。
258
258
 
259
259
  `Array#length` を参照した時に要素数を計算しているわけではなく、要素数の変動が起こる処理(Array#push, Array#filter等)の中で予め、length値を確定させています。
260
260
 

1

arrayLike のsetterコード修正

2019/05/14 13:48

投稿

think49
think49

スコア18166

test CHANGED
@@ -12,6 +12,8 @@
12
12
 
13
13
  Object.defineProperty(arrayLike, 'length', {
14
14
 
15
+ enumerable: true, configurable: true,
16
+
15
17
  get: function get () {
16
18
 
17
19
  return Object.keys(this).length;
@@ -28,7 +30,7 @@
28
30
 
29
31
  for (let i of Object.keys(this)) {
30
32
 
31
- if (+i.toString() === i && i > length) {
33
+ if ((+i).toString() === i && i >= length) {
32
34
 
33
35
  delete this[i];
34
36