-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathx15.3.html
710 lines (709 loc) · 31.3 KB
/
x15.3.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
<!DOCTYPE html>
<html class="split chapter"><head><meta charset="utf-8"><title>15.3 Function Objects # Ⓣ Ⓔ ① Ⓐ — Annotated ES5</title><link rel="stylesheet" href="style.css"><link href="x15.2.html" title="15.2 Object Objects " rel="prev">
<link href="spec.html" title="TOC" rel="index">
<link href="x15.4.html" title="15.4 Array Objects " rel="next">
</head><body><div class="head">
<h2 id="top">Annotated ECMAScript 5.1 <span id="timestamp"></span></h2>
<div id="mascot-treehouse">
<img id="mascot" align="left" src="js-mascot.svg" alt=""><img id="bubble" src="bubble.svg" alt=""></div>
<p id="slogan">‟Ex igne vita”</p>
<div id="annotations"></div>
<script src="timestamp.js"></script></div>
<nav>
<a href="x15.2.html">← 15.2 Object Objects </a> –
<a href="spec.html" class="toc-nav">TOC</a> –
<a href="x15.4.html">15.4 Array Objects →</a>
<ol class="toc"><li><ol><li><a href="x15.3.html#x15.3" id="x15.3-toc">15.3 Function Objects</a>
<b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> <ol><li><a href="x15.3.html#x15.3.1" id="x15.3.1-toc">15.3.1 The Function Constructor Called as a Function</a>
<b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> <ol><li><a href="x15.3.html#x15.3.1.1" id="x15.3.1.1-toc">15.3.1.1 Function (p1, p2, … , pn, body)</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li></ol></li><li><a href="x15.3.html#x15.3.2" id="x15.3.2-toc">15.3.2 The Function Constructor</a>
<b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> <ol><li><a href="x15.3.html#x15.3.2.1" id="x15.3.2.1-toc">15.3.2.1 new Function (p1, p2, … , pn, body)</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li></ol></li><li><a href="x15.3.html#x15.3.3" id="x15.3.3-toc">15.3.3 Properties of the Function Constructor</a>
<b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> <ol><li><a href="x15.3.html#x15.3.3.1" id="x15.3.3.1-toc">15.3.3.1 Function.prototype</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.3.html#x15.3.3.2" id="x15.3.3.2-toc">15.3.3.2 Function.length</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li></ol></li><li><a href="x15.3.html#x15.3.4" id="x15.3.4-toc">15.3.4 Properties of the Function Prototype Object</a>
<b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> <ol><li><a href="x15.3.html#x15.3.4.1" id="x15.3.4.1-toc">15.3.4.1 Function.prototype.constructor</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.3.html#x15.3.4.2" id="x15.3.4.2-toc">15.3.4.2 Function.prototype.toString ( )</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.3.html#x15.3.4.3" id="x15.3.4.3-toc">15.3.4.3 Function.prototype.apply (thisArg, argArray)</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.3.html#x15.3.4.4" id="x15.3.4.4-toc">15.3.4.4 Function.prototype.call (thisArg [ , arg1 [ , arg2, … ] ] )</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.3.html#x15.3.4.5" id="x15.3.4.5-toc">15.3.4.5 Function.prototype.bind (thisArg [, arg1 [, arg2, …]])</a>
<b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> <ol><li><a href="x15.3.html#x15.3.4.5.1" id="x15.3.4.5.1-toc">15.3.4.5.1 [[Call]]</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.3.html#x15.3.4.5.2" id="x15.3.4.5.2-toc">15.3.4.5.2 [[Construct]]</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.3.html#x15.3.4.5.3" id="x15.3.4.5.3-toc">15.3.4.5.3 [[HasInstance]] (V)</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li></ol></li></ol></li><li><a href="x15.3.html#x15.3.5" id="x15.3.5-toc">15.3.5 Properties of Function Instances</a>
<b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> <ol><li><a href="x15.3.html#x15.3.5.1" id="x15.3.5.1-toc">15.3.5.1 length</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.3.html#x15.3.5.2" id="x15.3.5.2-toc">15.3.5.2 prototype</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.3.html#x15.3.5.3" id="x15.3.5.3-toc">15.3.5.3 [[HasInstance]] (V)</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.3.html#x15.3.5.4" id="x15.3.5.4-toc">15.3.5.4 [[Get]] (P)</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li></ol></li></ol></li></ol></li></ol></nav>
<h3 id="x15.3" class="splitme">15.3 Function Objects <a href="#x15.3">#</a> <a href="#x15.3-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h3>
<h4 id="x15.3.1">15.3.1 The Function Constructor Called as a Function <a href="#x15.3.1">#</a> <a href="#x15.3.1-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h4>
<p>
When
<code><b>Function</b></code> is called
as a function rather than as a constructor, it creates and
initialises a new Function object. Thus the function call
<code><b>Function(</b></code><code>…</code><code><b>)</b></code>
is equivalent to the object creation expression <code><b>new
Function(</b></code><code>…</code><code><b>)</b></code>
with the same arguments.</p>
<h5 id="x15.3.1.1">15.3.1.1 Function (p1, p2, … , pn, body) <a href="#x15.3.1.1">#</a> <a href="#x15.3.1.1-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h5>
<p>
When
the <code><b>Function</b></code>
function is called with some arguments <i>p1</i>,
<i>p2</i>, … , <i>pn</i>,
<i>body</i> (where <i>n</i>
might be 0, that is,
there are no “<i>p</i>”
arguments, and where <i>body</i>
might also not be provided), the following steps are taken:</p>
<ol><li><p>
Create
and return a new Function object as if the standard built-in
constructor Function was used in a <b>new </b>expression with the
same arguments (<a href="#x15.3.2.1">15.3.2.1</a>).</p>
</li></ol><h4 id="x15.3.2">15.3.2 The Function Constructor <a href="#x15.3.2">#</a> <a href="#x15.3.2-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h4>
<p>
When
<code><b>Function</b></code> is called
as part of a <code><b>new</b></code>
expression, it is a constructor: it initialises the newly created
object.</p>
<h5 id="x15.3.2.1">15.3.2.1 new Function (p1, p2, … , pn, body) <a href="#x15.3.2.1">#</a> <a href="#x15.3.2.1-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h5>
<p>
The
last argument specifies the body (executable code) of a function;
any preceding arguments specify formal parameters.</p>
<p>
When
the <code><b>Function</b></code>
constructor is called with some arguments <i>p1</i>,
<i>p2</i>, … , <i>pn</i>,
<i>body</i> (where <i>n</i>
might be 0, that is,
there are no “<i>p</i>”
arguments, and where <i>body</i>
might also not be provided), the following steps are taken:</p>
<ol><li><p>
Let
<i>argCount</i> be the total number of arguments passed to this
function invocation.</p>
</li>
<li><p>
Let
<i>P</i> be the empty String.</p>
</li>
<li><p>
If
<i>argCount</i> = 0, let <i>body</i> be the empty String.</p>
</li>
<li><p>
Else
if <i>argCount</i> = 1, let <i>body</i> be that argument.</p>
</li>
<li><p>
Else,
<i>argCount</i> > 1</p>
<ol><li><p>
Let
<i>firstArg</i> be the first argument.</p>
</li>
<li><p>
Let
<i>P</i> be <a href="x9.html#x9.8">ToString</a>(<i>firstArg</i>).</p>
</li>
<li><p>
Let
<i>k</i> be 2.</p>
</li>
<li><p>
Repeat,
while <i>k</i> < <i>argCount</i></p>
<ol><li><p>
Let
<i>nextArg</i> be the <i>k</i>’<sup>th</sup> argument.</p>
</li>
<li><p>
Let
<i>P</i> be the result of concatenating the previous value of <i>P</i>,
the String <code><b>","</b></code>
(a comma), and <a href="x9.html#x9.8">ToString</a>(<i>nextArg</i>).</p>
</li>
<li><p>
Increase
<i>k</i> by 1.</p>
</li></ol></li>
<li><p>
Let
<i>body</i> be the <i>k</i>’<sup>th</sup> argument.</p>
</li></ol></li>
<li><p>
Let
<i>body</i> be <a href="x9.html#x9.8">ToString</a>(<i>body</i>).</p>
</li>
<li><p>
If
<i>P</i> is not parsable as a <i>FormalParameterList</i><sub>opt</sub>
then throw a <b><a href="x15.11.html#x15.11.6.4" class="term-ref">SyntaxError</a></b> exception.</p>
</li>
<li><p>
If
<i>body</i> is not parsable as <i><a href="x13.html#x13">FunctionBody</a></i> then throw a
<b><a href="x15.11.html#x15.11.6.4" class="term-ref">SyntaxError</a></b> exception.</p>
</li>
<li><p>
If<i>body </i>is <a href="x10.html#x10.1.1" class="term-ref">strict mode code</a> (see <a href="x10.html#x10.1.1">10.1.1</a>) then let <i>strict</i> be
<b>true</b>, else let <i>strict</i> be <b>false</b>.</p>
</li>
<li><p>
If
<i>strict</i> is <b>true</b>, throw any exceptions specified in
<a href="x13.html#x13.1">13.1</a> that apply.
</p>
</li>
<li><p>
Return
a new Function object created as specified in <a href="x13.html#x13.2">13.2</a> passing <i>P</i>
as the <i>FormalParameterList</i> and <i>body</i> as the
<i><a href="x13.html#x13">FunctionBody</a></i>. Pass in the <a href="x10.html#x10.2.3">Global Environment</a> as the <i>Scope</i>
parameter and <i>strict</i> as the <i>Strict</i> flag.</p>
</li></ol><p>
A
<code><b>prototype</b></code> property
is automatically created for every function, to provide for the
possibility that the function will be used as a constructor.</p>
<p>
</p><p><b class="note">NOTE</b> It
is permissible but not necessary to have one argument for each
formal parameter to be specified. For example, all three of the
following expressions produce the same result:</p>
<p class="code-example">
<code><b>new
Function("a", "b", "c", "return
a+b+c")</b></code></p>
<p class="code-example">
<code><b>new
Function("a, b, c", "return a+b+c")</b></code></p>
<p class="code-example">
<code><b>new
Function("a,b", "c", "return a+b+c")</b></code></p>
<h4 id="x15.3.3">15.3.3 Properties of the Function Constructor <a href="#x15.3.3">#</a> <a href="#x15.3.3-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h4>
<p>
The
Function constructor is itself a Function object and its [[Class]]
is <code><b>"Function"</b></code>.
The value of the [[Prototype]] internal property of the Function
constructor is the standard built-in Function prototype object
(<a href="#x15.3.4">15.3.4</a>).</p>
<p>
The
value of the [[Extensible]] internal property of the Function
constructor is <b>true</b>.</p>
<p>
The
Function constructor has the following properties:</p>
<h5 id="x15.3.3.1">15.3.3.1 Function.prototype <a href="#x15.3.3.1">#</a> <a href="#x15.3.3.1-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h5>
<p>
The
initial value of <code><b>Function.prototype</b></code>
is the standard built-in Function prototype object (<a href="#x15.3.4">15.3.4</a>).</p>
<p>
This
property has the attributes { [[Writable]]: <b>false</b>,
[[Enumerable]]: <b>false</b>, [[Configurable]]: <b>false</b> }.</p>
<h5 id="x15.3.3.2">15.3.3.2 Function.length <a href="#x15.3.3.2">#</a> <a href="#x15.3.3.2-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h5>
<p>
This
is a data property with a value of 1. This property has the
attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>,
[[Configurable]]: <b>false</b> }.</p>
<h4 id="x15.3.4">15.3.4 Properties of the Function Prototype Object <a href="#x15.3.4">#</a> <a href="#x15.3.4-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h4>
<p>
The
Function prototype object is itself a Function object (its [[Class]]
is <code><b>"Function"</b></code>)
that, when invoked, accepts any arguments and returns <b>undefined</b>.</p>
<p>
The
value of the [[Prototype]] internal property of the Function
prototype object is the standard built-in Object prototype object
(<a href="x15.2.html#x15.2.4">15.2.4</a>). The initial value of the [[Extensible]] internal property
of the Function prototype object is <b>true</b>.</p>
<p>
The
Function prototype object does not have a <code><b>valueOf</b></code>
property of its own; however, it inherits the <code><b>valueOf</b></code>
property from the Object prototype Object.</p>
<p>
The
<code><b>length</b></code> property of
the Function prototype object is <b>0</b>.</p>
<h5 id="x15.3.4.1">15.3.4.1 Function.prototype.constructor <a href="#x15.3.4.1">#</a> <a href="#x15.3.4.1-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h5>
<p>
The
initial value of <code><b>Function.prototype.constructor</b></code>
is the built-in <code><b>Function</b></code>
constructor.</p>
<h5 id="x15.3.4.2">15.3.4.2 Function.prototype.toString ( ) <a href="#x15.3.4.2">#</a> <a href="#x15.3.4.2-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h5>
<p>
An
implementation-dependent representation of the function is returned.
This representation has the syntax of a <i><a href="x13.html#x13">FunctionDeclaration</a></i>.
Note in particular that the use and placement of white space, line
terminators, and semicolons within the representation String is
implementation-dependent.</p>
<p>
The
<code><b>toString</b></code> function
is not generic; it throws a <b><a href="x15.11.html#x15.11.6.5" class="term-ref">TypeError</a></b> exception if its <b>this</b>
value is not a Function object. Therefore, it cannot be transferred
to other kinds of objects for use as a method.</p>
<h5 id="x15.3.4.3">15.3.4.3 Function.prototype.apply (thisArg, argArray) <a href="#x15.3.4.3">#</a> <a href="#x15.3.4.3-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h5>
<p>
When
the <code><b>apply</b></code> method
is called on an object <i>func</i>
with arguments <i>thisArg</i>
and <i>argArray</i>, the
following steps are taken:
</p>
<ol><li><p>
If
<a href="x9.html#x9.11">IsCallable</a>(<i>func</i>) is <b>false</b>, then throw a <b><a href="x15.11.html#x15.11.6.5" class="term-ref">TypeError</a></b>
exception.</p>
</li>
<li><p>
If
<i>argArray</i> is <b>null</b> or <b>undefined</b>, then</p>
<ol><li><p>
Return
the result of calling the [[Call]] internal method of <i>func</i>,
providing <i>thisArg</i> as the <b>this</b> value and an empty
list of arguments.</p>
</li></ol></li>
<li><p>
If
<a href="x8.html#Type">Type</a>(<i>argArray</i>) is not Object, then throw a <b><a href="x15.11.html#x15.11.6.5" class="term-ref">TypeError</a></b>
exception.</p>
</li>
<li><p>
Let
<i>len</i> be the result of calling the [[Get]] internal method of
<i>argArray</i> with argument <code><b>"length"</b></code>.</p>
</li>
<li><p>
Let
<i>n</i> be <a href="x9.html#x9.6">ToUint32</a>(<i>len</i>).</p>
</li>
<li><p>
Let
<i>argList</i> be an empty <a href="x8.html#x8.8">List</a>.</p>
</li>
<li><p>
Let
<i>index</i> be 0.</p>
</li>
<li><p>
Repeat
while <i>index</i> < <i>n</i></p>
<ol><li><p>
Let
<i>indexName</i> be <a href="x9.html#x9.8">ToString</a>(<i>index</i>).</p>
</li>
<li><p>
Let
<i>nextArg</i> be the result of calling the [[Get]] internal
method of <i>argArray</i> with <i>indexName</i> as the argument.</p>
</li>
<li><p>
Append
<i>nextArg</i> as the last element of <i>argList</i>.</p>
</li>
<li><p>
Set
<i>index</i> to <i>index</i> + 1.</p>
</li></ol></li>
<li><p>
Return
the result of calling the [[Call]] internal method of <i>func</i>,
providing <i>thisArg</i> as the <b>this</b> value and <i>argList</i>
as the list of arguments.</p>
</li></ol><p>
The
<code><b>length</b></code> property of
the <code><b>apply</b></code> method
is <b>2</b>.</p>
<p><b class="note">NOTE</b> The
thisArg value is passed without modification as the <b>this</b>
value. This is a change from Edition 3, where a <b>undefined</b> or
<b>null</b> thisArg is replaced with the <a href="x15.1.html#x15.1" class="term-ref">global object</a> and <a href="x9.html#x9.9">ToObject</a>
is applied to all other values and that result is passed as the <b>this</b>
value.</p>
<h5 id="x15.3.4.4">15.3.4.4 Function.prototype.call (thisArg [ , arg1 [ , arg2, … ] ] ) <a href="#x15.3.4.4">#</a> <a href="#x15.3.4.4-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h5>
<p>
When
the <code><b>call</b></code> method is
called on an object <i>func</i>
with argument <i>thisArg</i>
and optional arguments <i>arg1</i>,
<i>arg2</i> etc, the
following steps are taken:</p>
<ol><li><p>
If
<a href="x9.html#x9.11">IsCallable</a>(<i>func</i>) is <b>false</b>, then throw a <b><a href="x15.11.html#x15.11.6.5" class="term-ref">TypeError</a></b>
exception.</p>
</li>
<li><p>
Let
<i>argList</i> be an empty <a href="x8.html#x8.8">List</a>.</p>
</li>
<li><p>
If
this method was called with more than one argument then in left to
right order starting with <i>arg1</i> append each argument as the
last element of <i>argList</i></p>
</li>
<li><p>
Return
the result of calling the [[Call]] internal method of <i>func</i>,
providing <i>thisArg</i> as the <b>this</b> value and <i>argList</i>
as the list of arguments.</p>
</li></ol><p>
The
<code><b>length</b></code> property of
the <code><b>call</b></code> method is
<b>1</b>.</p>
<p><b class="note">NOTE</b> The
thisArg value is passed without modification as the <b>this</b>
value. This is a change from Edition 3, where a <b>undefined</b> or
<b>null</b> thisArg is replaced with the <a href="x15.1.html#x15.1" class="term-ref">global object</a> and <a href="x9.html#x9.9">ToObject</a>
is applied to all other values and that result is passed as the <b>this</b>
value.</p>
<h5 id="x15.3.4.5">15.3.4.5 Function.prototype.bind (thisArg [, arg1 [, arg2, …]]) <a href="#x15.3.4.5">#</a> <a href="#x15.3.4.5-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h5>
<p>
The
bind method takes one or more arguments, <i>thisArg</i>
and (optionally) <i>arg1</i>,
<i>arg2</i>, etc, and
returns a new function object by performing the following steps:</p>
<ol><li><p>
Let
<i>Target </i>be the <b>this </b>value.</p>
</li>
<li><p>
If
<a href="x9.html#x9.11">IsCallable</a>(<i>Target</i>) is <b>false</b>, throw a <b>TypeError
</b>exception.</p>
</li>
<li><p>
Let
<i>A </i>be a new (possibly empty) internal list of all of the
argument values provided after <i>thisArg </i>(<i>arg1</i>, <i>arg2</i>
etc), in order.</p>
</li>
<li><p>
Let
<i>F</i> be a new native ECMAScript object .</p>
</li>
<li><p>
Set
all the internal methods, except for [[Get]], of <i>F</i> as
specified in <a href="x8.html#x8.12">8.12</a>.</p>
</li>
<li><p>
Set
the [[Get]] internal property of <i>F </i>as specified in <a href="#x15.3.5.4">15.3.5.4</a>.</p>
</li>
<li><p>
Set
the [[TargetFunction]] internal property of <i>F </i>to <i>Target</i>.</p>
</li>
<li><p>
Set
the [[BoundThis]] internal property of <i>F</i> to the value of
<i>thisArg</i>.</p>
</li>
<li><p>
Set
the [[BoundArgs]] internal property of <i>F </i>to <i>A</i>.</p>
</li>
<li><p>
Set
the [[Class]] internal property of <i>F</i> to <b>"Function"</b>.</p>
</li>
<li><p>
Set
the [[Prototype]] internal property of <i>F </i>to the standard
built-in Function prototype object as specified in <a href="#x15.3.3.1">15.3.3.1</a>.</p>
</li>
<li><p>
Set
the [[Call]] internal property of <i>F </i>as described in
<a href="#x15.3.4.5.1">15.3.4.5.1</a>.</p>
</li>
<li><p>
Set
the [[Construct]] internal property of <i>F </i>as described in
<a href="#x15.3.4.5.2">15.3.4.5.2</a>.</p>
</li>
<li><p>
Set
the [[HasInstance]] internal property of <i>F </i>as described in
<a href="#x15.3.4.5.3">15.3.4.5.3</a>.</p>
</li>
<li><p>
If
the [[Class]] internal property of <i>Target </i>is <b>"Function"</b>,
then</p>
<ol><li><p>
Let
<i>L </i>be the <b>length </b>property of <i>Target </i>minus the
length of <i>A</i>.</p>
</li>
<li><p>
Set
the <b>length </b>own property of <i>F </i>to either 0 or
<i>L</i>, whichever is larger.
</p>
</li></ol></li>
<li><p>
Else
set the <b>length </b>own property of <i>F </i>to 0.</p>
</li>
<li><p>
Set
the attributes of the <b>length</b> own property of <i>F</i> to
the values specified in <a href="#x15.3.5.1">15.3.5.1</a>.</p>
</li>
<li><p>
Set
the [[Extensible]] internal property of <i>F</i> to <b>true</b>.</p>
</li>
<li><p>
Let
<i>thrower</i> be the [[ThrowTypeError]] function Object (<a href="x13.html#x13.2.3">13.2.3</a>).</p>
</li>
<li><p>
Call
the [[DefineOwnProperty]] internal method of <i>F</i> with
arguments <code><b>"caller"</b></code>,
PropertyDescriptor {[[Get]]: <i>thrower</i>, [[Set]]: <i>thrower</i>,
[[Enumerable]]: <b>false</b>, [[Configurable]]:<b> false</b>}, and
<b>false</b>.</p>
</li>
<li><p>
Call
the [[DefineOwnProperty]] internal method of <i>F</i> with
arguments <code><b>"arguments"</b></code>,
PropertyDescriptor {[[Get]]: <i>thrower</i>, [[Set]]: <i>thrower</i>,
[[Enumerable]]: <b>false</b>, [[Configurable]]: <b>false</b>}, and
<b>false</b>.</p>
</li>
<li><p>
Return
<i>F</i>.</p>
</li></ol><p>
The
<code><b>length</b></code> property of
the <code><b>bind</b></code> method is
<b>1</b>.</p>
<p><b class="note">NOTE</b> Function
objects created using <code><b>Function.prototype.bind</b></code>
do not have a <code><b>prototype</b></code>
property or the [[Code]], [[FormalParameters]], and [[Scope]]
internal properties.</p>
<h6 id="x15.3.4.5.1">15.3.4.5.1 [[Call]] <a href="#x15.3.4.5.1">#</a> <a href="#x15.3.4.5.1-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h6>
<p>
When
the [[Call]] internal method of a function object, <i>F</i>,
which was created using the bind function is called with a <b>this</b>
value and a list of arguments <i>ExtraArgs</i>,
the following steps are taken:</p>
<ol><li><p>
Let
<i>boundArgs</i> be the value of <i>F’s</i> [[BoundArgs]]
internal property.</p>
</li>
<li><p>
Let
<i>boundThis</i> be the value of <i>F’s</i> [[BoundThis]]
internal property.</p>
</li>
<li><p>
Let
<i>target</i> be the value of <i>F’s</i> [[TargetFunction]]
internal property.</p>
</li>
<li><p>
Let
<i>args</i> be a new list containing the same values as the list
<i>boundArgs</i> in the same order followed by the same values as
the list <i>ExtraArgs</i> in the same order.</p>
</li>
<li><p>
Return
the result of calling the [[Call]] internal method of <i>target</i>
providing <i>boundThis</i> as the <b>this </b>value and providing
<i>args</i> as the arguments.</p>
</li></ol><h6 id="x15.3.4.5.2">15.3.4.5.2 [[Construct]] <a href="#x15.3.4.5.2">#</a> <a href="#x15.3.4.5.2-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h6>
<p>
When
the [[Construct]] internal method of a function object, <i>F</i>
that was created using the bind function is called with a list of
arguments <i>ExtraArgs</i>,
the following steps are taken:</p>
<ol><li><p>
Let
<i>target</i> be the value of <i>F’s</i> [[TargetFunction]]
internal property.</p>
</li>
<li><p>
If
<i>target</i> has no [[Construct]] internal method, a <b><a href="x15.11.html#x15.11.6.5" class="term-ref">TypeError</a></b>
exception is thrown.</p>
</li>
<li><p>
Let
<i>boundArgs</i> be the value of <i>F’s</i> [[BoundArgs]]
internal property.</p>
</li>
<li><p>
Let
<i>args</i> be a new list containing the same values as the list
<i>boundArgs</i> in the same order followed by the same values as
the list <i>ExtraArgs</i> in the same order.</p>
</li>
<li><p>
Return
the result of calling the [[Construct]] internal method of<i>target</i> providing <i>args</i> as the arguments.</p>
</li></ol><h6 id="x15.3.4.5.3">15.3.4.5.3 [[HasInstance]] (V) <a href="#x15.3.4.5.3">#</a> <a href="#x15.3.4.5.3-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h6>
<p>
When
the [[HasInstance]] internal method of a function object <i>F</i>,
that was created using the bind function is called with argument <i>V</i>,
the following steps are taken:</p>
<ol><li><p>
Let
<i>target</i> be the value of <i>F’s</i> [[TargetFunction]]
internal property.</p>
</li>
<li><p>
If
<i>target</i> has no [[HasInstance]] internal method, a <b><a href="x15.11.html#x15.11.6.5" class="term-ref">TypeError</a></b>
exception is thrown.</p>
</li>
<li><p>
Return
the result of calling the [[HasInstance]] internal method of<i>target</i> providing <i>V</i> as the argument.</p>
</li></ol><h4 id="x15.3.5">15.3.5 Properties of Function Instances <a href="#x15.3.5">#</a> <a href="#x15.3.5-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h4>
<p>
In
addition to the required internal properties, every function
instance has a [[Call]] internal property and in most cases use a
different version of the [[Get]] internal property. Depending on how
they are created (see <a href="x8.html#x8.6.2">8.6.2</a> ,<a href="x13.html#x13.2">13.2</a>, 15, and <a href="#x15.3.4.5">15.3.4.5</a>), function
instances may have a [[HasInstance]] internal property, a [[Scope]]
internal property, a [[Construct]] internal property, a
[[FormalParameters]] internal property, a [[Code]] internal
property, a [[TargetFunction]] internal property, a [[BoundThis]]
internal property, and a [[BoundArgs]] internal property.</p>
<p>
The
value of the [[Class]] internal property is <b>"Function"</b>.</p>
<p>
Function
instances that correspond to strict mode functions (<a href="x13.html#x13.2">13.2</a>) and
function instances created using the <b>Function.prototype.bind
method</b> (<a href="#x15.3.4.5">15.3.4.5</a>) have properties named “caller” and
“arguments” that throw a <b><a href="x15.11.html#x15.11.6.5" class="term-ref">TypeError</a></b> exception. An
ECMAScript implementation must not associate any implementation
specific behaviour with accesses of these properties from strict
mode <a href="x10.html#function-code">function code</a>.
</p>
<h5 id="x15.3.5.1">15.3.5.1 length <a href="#x15.3.5.1">#</a> <a href="#x15.3.5.1-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h5>
<p>
The
value of the <code><b>length</b></code>
property is an integer that indicates the “typical” number of
arguments expected by the function. However, the language permits
the function to be invoked with some other number of arguments. The
behaviour of a function when invoked on a number of arguments other
than the number specified by its <code><b>length</b></code>
property depends on the function. This property has the attributes
{ [[Writable]]: <b>false</b>,
[[Enumerable]]: <b>false</b>,
[[Configurable]]: <b>false</b> }.</p>
<h5 id="x15.3.5.2">15.3.5.2 prototype <a href="#x15.3.5.2">#</a> <a href="#x15.3.5.2-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h5>
<p>
The
value of the <code><b>prototype</b></code>
property is used to initialise the [[Prototype]] internal property
of a newly created object before the Function object is invoked as a
constructor for that newly created object. This property has the
attribute { [[Writable]]: <b>true</b>,
[[Enumerable]]: <b>false</b>,
[[Configurable]]: <b>false</b>
}.</p>
<p><b class="note">NOTE</b> Function
objects created using <code><b><a href="#x15.3.4.5">Function.prototype.bind</a></b></code>
do not have a <code><b>prototype</b></code>
property.</p>
<h5 id="x15.3.5.3">15.3.5.3 [[HasInstance]] (V) <a href="#x15.3.5.3">#</a> <a href="#x15.3.5.3-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h5>
<p>
Assume
<i>F</i> is a Function
object.</p>
<p>
When
the [[HasInstance]] internal method of <i>F</i>
is called with value <i>V</i>,
the following steps are taken:</p>
<ol><li><p>
If
<i>V</i> is not an object, return <b>false</b>.</p>
</li>
<li><p>
Let
<i>O</i> be the result of calling the [[Get]] internal method of <i>F</i>
with property name <code><b>"prototype"</b></code>.</p>
</li>
<li><p>
If
<a href="x8.html#Type">Type</a>(<i>O</i>) is not Object, throw a <b><a href="x15.11.html#x15.11.6.5" class="term-ref">TypeError</a></b> exception.</p>
</li>
<li><p>
Repeat</p>
<ol><li><p>
Let
<i>V</i> be the value of the [[Prototype]] internal property of <i>V</i>.</p>
</li>
<li><p>
If
<i>V</i> is <code><b>null</b></code>,
return <b>false</b>.</p>
</li>
<li><p>
If
<i>O</i> and <i>V</i> refer to the same object, return <b>true</b>.</p>
</li></ol></li></ol><p class="sp">
</p><p><b class="note">NOTE</b> Function
objects created using <code><b><a href="#x15.3.4.5">Function.prototype.bind</a></b></code>
have a different implementation of [[HasInstance]] defined in
<a href="#x15.3.4.5.3">15.3.4.5.3</a>.</p>
<h5 id="x15.3.5.4">15.3.5.4 [[Get]] (P) <a href="#x15.3.5.4">#</a> <a href="#x15.3.5.4-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h5>
<p>
Function
objects use a variation of the [[Get]] internal method used for
other native ECMAScript objects (<a href="x8.html#x8.12.3">8.12.3</a>).</p>
<p>
Assume
<i>F</i> is a Function
object. When the [[Get]] internal method of <i>F</i>
is called with property name <i>P</i>,
the following steps are taken:</p>
<ol><li><p>
Let
<i>v</i> be the result of calling the default [[Get]] internal
method (<a href="x8.html#x8.12.3">8.12.3</a>) on <i>F</i> passing <i>P</i> as the property name
argument.</p>
</li>
<li><p>
If
<i>P</i> is <code><b>"caller"
</b></code>and <i>v</i> is a strict mode Function object, throw a
<b><a href="x15.11.html#x15.11.6.5" class="term-ref">TypeError</a></b> exception.
</p>
</li>
<li><p>
Return
<i>v</i>.</p>
</li></ol><p><b class="note">NOTE</b> Function
objects created using <code><b><a href="#x15.3.4.5">Function.prototype.bind</a></b></code>
use the default [[Get]] internal method.</p>
</body><script src="anno.js"></script></html>