clone()
方法在
响应
interface creates a clone of a response object, identical in every way, but stored in a different variable.
clone()
throws a
TypeError
if the response
Body
has already been used. In fact, the main reason
clone()
exists is to allow multiple uses of
Body
objects (when they are one-use only.)
var response2 = response1.clone();
None.
A
响应
对象。
In our
Fetch Response clone example
(见
Fetch Response clone live
) we create a new
Request
对象使用
Request()
constructor, passing it a JPG path. We then fetch this request using
fetch()
. When the fetch resolves successfully, we clone it, extract a blob from both responses using two
Body.blob
calls, create object URLs out of the blobs using
URL.createObjectURL
, and display them in two separate
<img>
元素。
var image1 = document.querySelector('.img1');
var image2 = document.querySelector('.img2');
var myRequest = new Request('flowers.jpg');
fetch(myRequest).then(function(response) {
var response2 = response.clone();
response.blob().then(function(myBlob) {
var objectURL = URL.createObjectURL(myBlob);
image1.src = objectURL;
});
response2.blob().then(function(myBlob) {
var objectURL = URL.createObjectURL(myBlob);
image2.src = objectURL;
});
});
| 规范 | 状态 | 注释 |
|---|---|---|
|
Fetch
The definition of 'clone()' in that specification. |
实时标准 | 初始定义 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
clone
|
Chrome
42
|
Edge 14 |
Firefox
39
|
IE No |
Opera
29
|
Safari No | WebView Android No | Chrome Android No | Firefox Android No |
Opera Android
29
|
Safari iOS No | Samsung Internet Android No |
完整支持
不支持
实验。期望将来行为有所改变。
用户必须明确启用此特征。
响应