箭头函数中的“未捕获类型错误:this._isDateType 不是函数”

2024-03-06

每次我都会遇到找不到函数定义的类型错误。代码如下:

return BaseController.extend("ch.micarna.weightprotocol.controller.Calendar", {
  onInit: function () {
    console.log(this._isDateType(new Date()));
    let oHbox = this.byId("calendar-container");
    let oTodayDate = new Date();
    let oEndDate = this._getLastDayOfMonth(oTodayDate);
  },

  _getLastDayOfMonth: (oBegin) => {
    if (this._isDateType(oBegin)) {
      throw new TypeError("The given parameter is not type of date.");
    }
    return new Date(oBegin.getFullYear(), oBegin.getMonth() + 1, 0);
  },

  _isDateType: (oDate) => {
    return Object.prototype.toString.call(oDate) === "[object Date]";
  },

});

问题是_isDateType在内部调用时找不到该函数_getLastDayOfMonth功能。 我设置了断点:

正如你所看到的,该函数未定义,我不知道为什么。

年初时onInit函数,我称之为_isDateType功能:

console.log(this._isDateType(new Date()));

它提供了预期的结果。

我究竟做错了什么?


Replace the arrow function

_getLastDayOfMonth: (oBegin) => {
  // this....
},
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

箭头函数中的“未捕获类型错误:this._isDateType 不是函数” 的相关文章

随机推荐