Javascript Angular HttpResponse.clone()不创建新对象

Javascript Angular HttpResponse.clone()不创建新对象,javascript,angular,Javascript,Angular,我已经基于创建了一个小型缓存拦截器,并且发现,HttpResponse.clone()返回相同的引用,而不是创建新对象。我很期待它像一个复制构造函数一样工作,或者创建我的响应对象的深度副本。Angular文档没有对预期行为进行太多说明: 我创建了一个小示例: 正如您在控制台中看到的,第一个缓存的响应是正确的,但是如果我在收到的Http响应中更改了某些内容,我就是在更改原始对象,就像clone()返回的标准JS对象引用一样 // Interceptor cache: Map<string

我已经基于创建了一个小型缓存拦截器,并且发现,
HttpResponse.clone()
返回相同的引用,而不是创建新对象。我很期待它像一个复制构造函数一样工作,或者创建我的响应对象的深度副本。Angular文档没有对预期行为进行太多说明:

我创建了一个小示例:

正如您在控制台中看到的,第一个缓存的响应是正确的,但是如果我在收到的Http响应中更改了某些内容,我就是在更改原始对象,就像
clone()
返回的标准JS对象引用一样

// Interceptor
cache: Map<string, HttpResponse<any>> = new Map();

intercept(
// ...
  if (cachedResponse) {
    return of(cachedResponse.clone());
  else {
    return next.handle(req);
  }
)

// Subscription in the component
this.http.get<any>(url).subscribe(res => {
  res.title = "Invalid title!"; // cached data in interceptor is modified!
//拦截器

cache:MapThis:“HttpResponse.clone()返回引用而不是新对象的行为是否符合预期?”实际情况并非如此。它是一个完全相同的副本,但它不是相同的参考。不符合克隆方法的要求。为了向自己证明这一点,请将此代码添加到Blitz的第30行:
console.log(cachedResponse.clone()==cachedResponse)-它将返回
false
,因为它们不是相同的引用。谢谢。查看clone()实现,主体是通过引用传递的,这导致了问题。
return of(JSON.parse(JSON.stringify(cachedResponse.clone()))); <--this works