【问题标题】:What does History.length class method do?History.length 类方法有什么作用?
【发布时间】:2019-01-28 20:14:51
【问题描述】:

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

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

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

【问题讨论】:

标签: javascript html browser browser-history html5-history


【解决方案1】:

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

Function.length on MDN:

length 属性表示函数期望的参数数量。

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));

【讨论】:

  • @Luca — 请参阅该页面的语法部分。它在谈论history 而不是History
  • 是的,MDN 在History.lengthhistory.length 之间切换让我有点困惑
  • 您能否添加一个关于它为什么有用的部分?或者那可能是题外话
  • @JanWillemHuising — 我从来没有发现它有用。有趣,但没用。
  • 实例实现接口,构造函数不实现,它们的输出(实例)实现
猜你喜欢
  • 2014-08-22
  • 1970-01-01
  • 2015-04-07
  • 2018-10-23
  • 2011-09-01
  • 2010-11-03
  • 2019-09-19
  • 2012-06-27
  • 2016-02-19
相关资源
最近更新 更多