blob: 8b5e3a185a67e457bd23c3b0bd87d063563a76ef (
plain)
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
|
---
title: Request.clone()
slug: Web/API/Request/clone
tags:
- API
- Experimenal
- Fetch
- Method
- Reference
- clone
- request
translation_of: Web/API/Request/clone
---
<div>{{APIRef("Fetch")}}{{SeeCompatTable}}</div>
<p>{{domxref("Request")}} インターフェースの <strong><code>clone()</code></strong> メソッドは、現在の <code>Request</code> オブジェクトのコピーを生成します。</p>
<p>レスポンス {{domxref("Body")}} が既に使用されていた場合、<code>clone()</code> は {{jsxref("TypeError")}} をスローします。はっきりと言えば、<code>clone()</code> が存在する主な理由は、{{domxref("Body")}} オブジェクトを(それらが 1 回しか使用できない時に)複数回使用するためです。</p>
<h2 id="構文">構文</h2>
<pre class="brush: js">var newRequest = request.clone();</pre>
<h3 id="パラメータ">パラメータ</h3>
<p>なし。</p>
<h3 id="戻り値">戻り値</h3>
<p>clone( ) が呼び出された Request の精密なコピーである {{domxref("Request")}} オブジェクト。</p>
<h2 id="例">例</h2>
<p>次のスニペットは、{{domxref("Request.Request()")}} コンストラクタを使って(スクリプトと同じディレクトリにある画像ファイルのために)新しいリクエストを生成してから、リクエストをコピーしています。</p>
<pre class="brush: js">var myRequest = new Request('flowers.jpg');
var newRequest = myRequest.clone(); // リクエストのコピーが newRequest に保存されます。</pre>
<h2 id="仕様">仕様</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">仕様</th>
<th scope="col">状態</th>
<th scope="col">コメント</th>
</tr>
<tr>
<td>{{SpecName('Fetch','#dom-request-clone','clone')}}</td>
<td>{{Spec2('Fetch')}}</td>
<td>Initial definition</td>
</tr>
</tbody>
</table>
<h2 id="ブラウザ実装状況">ブラウザ実装状況</h2>
<p>{{Compat("api.Request.clone")}}</p>
<h2 id="関連項目">関連項目</h2>
<ul>
<li><a href="/ja/docs/Web/API/ServiceWorker_API">ServiceWorker API</a></li>
<li><a href="/ja/docs/Web/HTTP/Access_control_CORS">HTTP access control (CORS)</a></li>
<li><a href="/ja/docs/Web/HTTP">HTTP</a></li>
</ul>
|