知道为什么这在 Chrome 中不起作用吗?
var foo = (new Date).getDate;<br/>
foo();
我得到一个 TypeError: this is not a Date object。然而(new Date).getDate()
作品
最佳答案
您的示例中的函数未正确绑定(bind)。该 foo 调用的“this”对象不是原始日期对象。
使逻辑工作的一种方法是绑定(bind)函数:
var x = new Date();
var foo = x.getDate.bind(x);
foo();
关于javascript - 类型错误 : this is not a Date object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17899598/