javascript - History.length 类方法有什么作用?

标签 javascript html browser browser-history html5-history

我通常使用window.history来访问Historyweb API ,但是我注意到在 MDN 上,全局 History 对象上有静态单例方法/属性,例如 History.length

我注意到 History.length 返回 0 是不正确的,而 window.history.length 返回 非零 正确的值。

前者的目的是什么?为什么它返回错误的值?

最佳答案

History 构造函数的 length 属性与任何函数相同。

参见Function.length on MDN :

The length property indicates the number of arguments expected by the function.

function foo() {};
function bar(a, b, c) {};
console.log({ foo: foo.length, bar: bar.length });

console.log("History is a " + typeof History);
console.log("history is a " + typeof history);
console.log("History is the same as history? " + (History == history));

关于javascript - History.length 类方法有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51969036/

相关文章:

javascript - 悬停时如何制作选取框 - 文本滚动和无限循环,悬停 - 回到起始位置?

javascript - 主干 model.unset 不删除属性

c# - 如何将 HTML 转换为纯文本

html - 媒体不能在<视频>和<音频>中播放

javascript - 捕获浏览器的音量事件

javascript - javascript 代码需要以 "&lt;!-- "开头吗?

javascript - 如何使用一个函数改变另一个函数的属性?

html - 图中的表格 - 使用标题或图形标题?

html - 如何在 bootstrap 3 轮播中对齐多列?

javascript - 如何调用memorystream到浏览器下载?