回答編集履歴

2

Array#lengthのmarkdownをJavaScriptコードブロックにした

2015/10/20 03:57

投稿

think49
think49

スコア18162

test CHANGED
@@ -36,7 +36,7 @@
36
36
 
37
37
 
38
38
 
39
- ```
39
+ ```JavaScript
40
40
 
41
41
  function sum (a, b) { return a + b; }
42
42
 

1

Function#length のサンプルコードで sum.length = 3; で正常処理するよう書いていたが、実際には TypeError が発生していたので修正

2015/10/20 03:57

投稿

think49
think49

スコア18162

test CHANGED
@@ -40,11 +40,11 @@
40
40
 
41
41
  function sum (a, b) { return a + b; }
42
42
 
43
- sum.length = 3;
43
+ sum.length = 3; // TypeError: Cannot assign to read only property 'length' of function sum(a, b) { return a + b; }
44
44
 
45
- console.log(sum.length; // 2
45
+ console.log(sum.length); // 2
46
46
 
47
- console.log(Object.getOwnPropertyDescriptor(array, 'length')); // {value: 1, writable: true, enumerable: false, configurable: false}
47
+ console.log(Object.getOwnPropertyDescriptor(sum, 'length')); // Object {value: 2, writable: false, enumerable: false, configurable: true}
48
48
 
49
49
  ```
50
50