From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/api/request/clone/index.html | 62 ++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 files/zh-cn/web/api/request/clone/index.html (limited to 'files/zh-cn/web/api/request/clone') diff --git a/files/zh-cn/web/api/request/clone/index.html b/files/zh-cn/web/api/request/clone/index.html new file mode 100644 index 0000000000..a256435381 --- /dev/null +++ b/files/zh-cn/web/api/request/clone/index.html @@ -0,0 +1,62 @@ +--- +title: Request.clone() +slug: Web/API/Request/clone +translation_of: Web/API/Request/clone +--- +
{{APIRef("Fetch")}}
+ +
+ +

 {{domxref("Request")}} 接口中的clone() 方法可以创建一个当前Request 对象的副本。

+ +

 如果响应体{{domxref("Body")}}已经被使用过,那么clone()会抛出一个{{jsxref("TypeError")}}。实际上,clone() 的主要作用就是支持{{domxref("Body")}}对象的多次使用

+ +

语法

+ +
var newRequest = request.clone();
+ +

参数

+ +

无。

+ +

返回值

+ +

{{domxref("Request")}}对象,也就是Request的完整拷贝

+ +

示例

+ +

在下面的代码中,我们使用{{domxref("Request.Request()")}}构造函数创建了一个新的request对象(请求当前文件夹中的一个图片文件),然后拷贝了这个request对象。

+ +
var myRequest = new Request('flowers.jpg');
+var newRequest = myRequest.clone(); // a copy of the request is now stored in newRequest
+ +

规范

+ + + + + + + + + + + + + + +
规范状态说明
{{SpecName('Fetch','#dom-request-clone','clone')}}{{Spec2('Fetch')}}初始化定义
+ +

浏览器兼容性

+ + + +

{{Compat("api.Request.clone")}}

+ +

了解更多

+ + -- cgit v1.2.3-54-g00ecf