window.location.assign(url) vs window.location = url?

window.location.assign(url) vs window.location = url?

我想知道使用一个与另一个的论据是什么。我熟悉 window.location.pathname 等其他属性。但据我所知,分配给 window.location 与调用 window.location.assign 并将其传递给 url.

具有相同的行为

为什么使用其中之一?我更喜欢 assign 因为它更明确,而分配给 window.location 在其 setter.

中具有隐含的、隐藏的魔法

是否有理由支持其中之一?

是一样的:

Whenever a new value is assigned to the location object, a document will be loaded using the URL as if location.assign() had been called with the modified URL. Note that security settings, like CORS, may prevent this to effectively happen. (https://developer.mozilla.org/en-US/docs/Web/API/Window/location)