forked from swiftwasm/JavaScriptKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
293 lines (268 loc) · 13.9 KB
/
index.html
File metadata and controls
293 lines (268 loc) · 13.9 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JavaScriptKit - JSFunction</title>
<link rel="stylesheet" type="text/css" href="/JavaScriptKit/all.css" media="all" />
</head>
<body>
<header>
<a href="/JavaScriptKit">
<strong>
JavaScriptKit
</strong>
<span>Documentation</span>
</a>
</header>
<!--
<form class="search">
<input type="search" placeholder="Search" />
</form>
-->
<nav>
<div class="wrapper">
<h2>On This Page</h2>
<ol><li><a href="#relationships">Relationships</a><ul><li><a href="#relationships">Superclass</a></li></ul></li><li><a href="#properties">Properties</a><ul><li class="variable"><a href="#jsfunction.`throws`">`throws`</a></li></ul></li><li><a href="#methods">Methods</a><ul><li class="function"><a href="#jsfunction.callasfunction(this:arguments:)">callAsFunction(this:arguments:)</a></li><li class="function"><a href="#jsfunction.callasfunction(this:_:)">callAsFunction(this:_:)</a></li><li class="function"><a href="#jsfunction.new(arguments:)">new(arguments:)</a></li><li class="function"><a href="#jsfunction.new(_:)">new(_:)</a></li><li class="function"><a href="#jsfunction.from(_:)">from(_:)</a></li><li class="function"><a href="#jsfunction.construct(from:)">construct(from:)</a></li><li class="function"><a href="#jsfunction.jsvalue()">jsValue()</a></li></ul></li></ol>
</div>
</nav>
<main>
<article>
<h1>
<small>Class</small>
<code class="name">JSFunction</code>
</h1>
<div class="declaration">
<pre class="highlight"><code><html><body><span class="keyword">public</span> <span class="keyword">class</span> <span class="type">JSFunction</span>: <a href="/JavaScriptKit/JSObject"><span class="type">JSObject</span></a> </body></html></code></pre>
</div>
<div class="summary" role="doc-abstract">
<p><code>JSFunction</code> represents a function in JavaScript and supports new object instantiation.
This type can be callable as a function using <code>callAsFunction</code>.</p>
</div>
<div class="discussion">
<p>e.g.</p>
<html><body><pre class="highlight"><code><span class="keyword">let</span> <span class="variable">alert</span>: <span class="type">JSFunction</span> = <span class="variable">JSObject</span>.<span class="variable">global</span>.<span class="variable">alert</span>.<span class="variable">function</span>!
<span class="comment">// Call `JSFunction` as a function</span>
<span class="variable">alert</span>(<span class="string literal">"</span><span class="string literal">Hello, world</span><span class="string literal">"</span>)
</code></pre></body></html>
</div>
<section id="relationships">
<h2 hidden>Relationships</h2>
<figure>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.40.1 (20161225.0304)
-->
<!-- Title: %69 Pages: 1 -->
<svg width="872pt" height="116pt"
viewBox="0.00 0.00 872.00 116.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 112)">
<title>%69</title>
<polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-112 868,-112 868,4 -4,4"/>
<!-- JSFunction -->
<g id="node1" class="node class current">
<title>JSFunction</title>
<g id="a_node1"><a xlink:href="/JavaScriptKit/JSFunction" xlink:title="JSFunction">
<path fill="none" stroke="#000000" stroke-width="3" d="M528,-108C528,-108 336,-108 336,-108 330,-108 324,-102 324,-96 324,-96 324,-84 324,-84 324,-78 330,-72 336,-72 336,-72 528,-72 528,-72 534,-72 540,-78 540,-84 540,-84 540,-96 540,-96 540,-102 534,-108 528,-108"/>
<text text-anchor="middle" x="432" y="-86.3" font-family="Menlo" font-size="14.00" fill="#000000">JSFunction</text>
</a>
</g>
</g>
<!-- JSObject -->
<g id="node2" class="node class">
<title>JSObject</title>
<g id="a_node2"><a xlink:href="/JavaScriptKit/JSObject" xlink:title="JSObject">
<path fill="none" stroke="#000000" d="M528,-36C528,-36 336,-36 336,-36 330,-36 324,-30 324,-24 324,-24 324,-12 324,-12 324,-6 330,0 336,0 336,0 528,0 528,0 534,0 540,-6 540,-12 540,-12 540,-24 540,-24 540,-30 534,-36 528,-36"/>
<text text-anchor="middle" x="432" y="-14.3" font-family="Menlo" font-size="14.00" fill="#000000">JSObject</text>
</a>
</g>
</g>
<!-- JSFunction->JSObject -->
<g id="edge1" class="edge inheritsFrom">
<title>JSFunction->JSObject</title>
<path fill="none" stroke="#000000" d="M432,-71.8314C432,-64.131 432,-54.9743 432,-46.4166"/>
<polygon fill="#000000" stroke="#000000" points="435.5001,-46.4132 432,-36.4133 428.5001,-46.4133 435.5001,-46.4132"/>
</g>
</g>
</svg>
<figcaption hidden>Inheritance graph for JSFunction.</figcaption>
</figure>
<h3>Superclass</h3>
<dl>
<dt class="class"><code><a href="/JavaScriptKit/JSObject">JSObject</a></code></dt>
<dd><p><code>JSObject</code> represents an object in JavaScript and supports dynamic member lookup.
Any member access like <code>object.foo</code> will dynamically request the JavaScript and Swift
runtime bridge library for a member with the specified name in this object.</p>
</dd>
</dl>
</section>
<section id="properties">
<h2>Properties</h2>
<div role="article" class="variable" id="jsfunction.`throws`">
<h3>
<code><a href="#jsfunction.`throws`">`throws`</a></code>
</h3>
<div class="declaration">
<pre class="highlight"><code><html><body><span class="keyword">public</span> <span class="keyword">var</span> <span class="variable">`throws`</span>: <a href="/JavaScriptKit/JSThrowingFunction"><span class="type">JSThrowingFunction</span></a> </body></html></code></pre>
</div>
<div class="summary" role="doc-abstract">
<p>A modifier to call this function as a throwing function</p>
</div>
<div class="discussion">
<html><body><pre><code class="language-javascript">function validateAge(age) {
if (age < 0) {
throw new Error("Invalid age");
}
}
</code></pre>
</body></html>
<html><body><pre class="highlight"><code><span class="keyword">let</span> <span class="variable">validateAge</span> = <span class="variable">JSObject</span>.<span class="variable">global</span>.<span class="variable">validateAge</span>.<span class="variable">function</span>!
<span class="keyword">try</span> <span class="variable">validateAge</span>.<span class="variable">throws</span>(<span class="number literal">20</span>)
</code></pre></body></html>
</div>
</div>
</section>
<section id="methods">
<h2>Methods</h2>
<div role="article" class="function" id="jsfunction.callasfunction(this:arguments:)">
<h3>
<code><a href="#jsfunction.callasfunction(this:arguments:)">callAsFunction(this:arguments:)</a></code>
</h3>
<div class="declaration">
<pre class="highlight"><code><html><body><span class="attribute">@</span><span class="attribute">discardableResult</span>
<span class="keyword">public</span> <span class="keyword">func</span> <span class="function">callAsFunction</span>(<span class="variable">this</span>: <a href="/JavaScriptKit/JSObject"><span class="type">JSObject</span></a>? = <span class="keyword">nil</span>, <span class="variable">arguments</span>: [<a href="/JavaScriptKit/ConvertibleToJSValue"><span class="type">ConvertibleToJSValue</span></a>]) -> <a href="/JavaScriptKit/JSValue"><span class="type">JSValue</span></a> </body></html></code></pre>
</div>
<div class="summary" role="doc-abstract">
<p>Call this function with given <code>arguments</code> and binding given <code>this</code> as context.</p>
</div>
<h4>Parameters</h4>
<table class="parameters">
<thead hidden>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<th>this</th>
<td><code class="type">JSObject?</code></td>
<td><p>The value to be passed as the <code>this</code> parameter to this function.</p>
</td>
</tr>
<tr>
<th>arguments</th>
<td><code class="type">[ConvertibleToJSValue]</code></td>
<td><p>Arguments to be passed to this function.</p>
</td>
</tr>
</tbody>
</table>
<h4>Returns</h4>
<p>The result of this call.</p>
</div>
<div role="article" class="function" id="jsfunction.callasfunction(this:_:)">
<h3>
<code><a href="#jsfunction.callasfunction(this:_:)">callAsFunction(this:_:)</a></code>
</h3>
<div class="declaration">
<pre class="highlight"><code><html><body><span class="attribute">@</span><span class="attribute">discardableResult</span>
<span class="keyword">public</span> <span class="keyword">func</span> <span class="function">callAsFunction</span>(<span class="variable">this</span>: <a href="/JavaScriptKit/JSObject"><span class="type">JSObject</span></a>? = <span class="keyword">nil</span>, <span class="keyword">_</span> <span class="variable">arguments</span>: <a href="/JavaScriptKit/ConvertibleToJSValue"><span class="type">ConvertibleToJSValue</span></a>...) -> <a href="/JavaScriptKit/JSValue"><span class="type">JSValue</span></a> </body></html></code></pre>
</div>
<div class="summary" role="doc-abstract">
<p>A variadic arguments version of <code>callAsFunction</code>.</p>
</div>
</div>
<div role="article" class="function" id="jsfunction.new(arguments:)">
<h3>
<code><a href="#jsfunction.new(arguments:)">new(arguments:)</a></code>
</h3>
<div class="declaration">
<pre class="highlight"><code><html><body><span class="keyword">public</span> <span class="keyword">func</span> <span class="function">new</span>(<span class="variable">arguments</span>: [<a href="/JavaScriptKit/ConvertibleToJSValue"><span class="type">ConvertibleToJSValue</span></a>]) -> <a href="/JavaScriptKit/JSObject"><span class="type">JSObject</span></a> </body></html></code></pre>
</div>
<div class="summary" role="doc-abstract">
<p>Instantiate an object from this function as a constructor.</p>
</div>
<div class="discussion">
<p>Guaranteed to return an object because either:</p>
<ul>
<li>
<p>a. the constructor explicitly returns an object, or</p>
</li>
<li>
<p>b. the constructor returns nothing, which causes JS to return the <code>this</code> value, or</p>
</li>
<li>
<p>c. the constructor returns undefined, null or a non-object, in which case JS also returns <code>this</code>.</p>
</li>
</ul>
</div>
<h4>Parameters</h4>
<table class="parameters">
<thead hidden>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<th>arguments</th>
<td><code class="type">[ConvertibleToJSValue]</code></td>
<td><p>Arguments to be passed to this constructor function.</p>
</td>
</tr>
</tbody>
</table>
<h4>Returns</h4>
<p>A new instance of this constructor.</p>
</div>
<div role="article" class="function" id="jsfunction.new(_:)">
<h3>
<code><a href="#jsfunction.new(_:)">new(_:)</a></code>
</h3>
<div class="declaration">
<pre class="highlight"><code><html><body><span class="keyword">public</span> <span class="keyword">func</span> <span class="function">new</span>(<span class="keyword">_</span> <span class="variable">arguments</span>: <a href="/JavaScriptKit/ConvertibleToJSValue"><span class="type">ConvertibleToJSValue</span></a>...) -> <a href="/JavaScriptKit/JSObject"><span class="type">JSObject</span></a> </body></html></code></pre>
</div>
<div class="summary" role="doc-abstract">
<p>A variadic arguments version of <code>new</code>.</p>
</div>
</div>
<div role="article" class="function" id="jsfunction.from(_:)">
<h3>
<code><a href="#jsfunction.from(_:)">from(_:)</a></code>
</h3>
<div class="declaration">
<pre class="highlight"><code><html><body><span class="attribute">@</span><span class="attribute">available</span>(*, <span class="variable">unavailable</span>, <span class="variable">message</span>: <span class="string literal">"Please use JSClosure instead"</span>)
<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">func</span> <span class="function">from</span>(<span class="keyword">_</span>: <span class="attribute">@</span><span class="attribute">escaping</span> ([<a href="/JavaScriptKit/JSValue"><span class="type">JSValue</span></a>]) -> <a href="/JavaScriptKit/JSValue"><span class="type">JSValue</span></a>) -> <a href="/JavaScriptKit/JSFunction"><span class="type">JSFunction</span></a> </body></html></code></pre>
</div>
</div>
<div role="article" class="function" id="jsfunction.construct(from:)">
<h3>
<code><a href="#jsfunction.construct(from:)">construct(from:)</a></code>
</h3>
<div class="declaration">
<pre class="highlight"><code><html><body><span class="keyword">public</span> <span class="attribute">override</span> <span class="keyword">class</span> <span class="keyword">func</span> <span class="function">construct</span>(<span class="variable">from</span> <span class="variable">value</span>: <a href="/JavaScriptKit/JSValue"><span class="type">JSValue</span></a>) -> <span class="keyword">Self</span>? </body></html></code></pre>
</div>
</div>
<div role="article" class="function" id="jsfunction.jsvalue()">
<h3>
<code><a href="#jsfunction.jsvalue()">jsValue()</a></code>
</h3>
<div class="declaration">
<pre class="highlight"><code><html><body><span class="attribute">override</span> <span class="keyword">public</span> <span class="keyword">func</span> <span class="function">jsValue</span>() -> <a href="/JavaScriptKit/JSValue"><span class="type">JSValue</span></a> </body></html></code></pre>
</div>
</div>
</section>
</article>
</main>
<footer>
<p>
Generated on <time datetime="2022-03-24T11:42:53+0000">March 24, 2022</time> using <a href="https://github.com/SwiftDocOrg/swift-doc">swift-doc</a> <span class="version">1.0.0-rc.1</span>.
</p>
</footer>
</body>
</html>