Request
接口中的clone()
方法可以创建一个当前Request
对象的副本。
如果响应体Body
已经被使用过,那么clone()会抛出一个
TypeError
。实际上,clone()
的主要作用就是支持Body
对象的多次使用
语法
var newRequest = request.clone();
参数
无。
返回值
Request
对象,也就是Request的完整拷贝
示例
在下面的代码中,我们使用Request.Request()
构造函数创建了一个新的request对象(请求当前文件夹中的一个图片文件),然后拷贝了这个request对象。
var myRequest = new Request('flowers.jpg');
var newRequest = myRequest.clone(); // a copy of the request is now stored in newRequest
规范
规范 | 状态 | 说明 |
---|---|---|
Fetch clone |
Living Standard | 初始化定义 |
浏览器兼容性
BCD tables only load in the browser
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.