我通常使用window.history
来访问History
web API ,但是我注意到在 MDN 上,全局 History
对象上有静态单例方法/属性,例如 History.length
。
我注意到 History.length
返回 0
是不正确的,而 window.history.length
返回 非零
正确的值。
前者的目的是什么?为什么它返回错误的值?
最佳答案
History
构造函数的 length
属性与任何函数相同。
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/