beatPicker使用出现Uncaught ReferenceError: module is not defined

来源:互联网 发布:php中级开发工程师 编辑:程序博客网 时间:2024/05/18 17:26

     最近用到了beatpicker时间选择插件,但在使用中却遇到了一个问题,多次在其他页面切换时会出现“VM2358:1494 Uncaught ReferenceError: module is not defined”这个异常,测试组的同事说这个问题是在自己来回切换几个页面时出现的这个问题,我进行测试时确实会出现这个问题,后来找到产生这个异常根本无需在多个页面之间来回切换,只需在其中一个页面与我负责的页面之间切换下就会出现,到这里我特想推荐一本书:你以为你以为的就是你以为的吗偷笑

      好了废话不多说,现在直入主题,问题的根本在于BeatPicker的原作者在设计这个插件的时候埋下了一个bug,这个bug的位置代码为:

_markToday: function (date) {
        if (this.modules.today) {
            date = date || this.currentDate;
            this._todayNode && this._todayNode.removeClass(this.className._inner.todayInGrid).removeClass(this.className.todayBox);
            for (var i in this._dateRows) {
             //debugger;
/*             if(this._dateRows[i].data==undefined){
             debugger;
             console.log("this._dateRows[i].data==undefined");
             continue;
             }*/

                if (this._dateEqualsTo(this._dateRows[i].data("date"), date)) {
                    this._todayNode = this._dateRows[i];
                    $(this._dateRows[i]).addClass(this.className._inner.todayInGrid).addClass(this.className.todayBox);
                }
            }
        }
    }

看到我用黄色注释掉的部分了吧,作者使用for in这种方式来便利Array数组,这就是问题所在,如果其他地方使用Array.prototype的方式来创建了一个方法,那么这种便利就会在“this._dateRows[i].data("date")”处出现异常,所以可以修改便利数组的方式,或者打开我用黄色注释掉的部分,这里再推荐一篇文章:点击打开链接


JavaScript也需要编码规范,有些使用方式会在未来的集成中可能引发bug

1 0
原创粉丝点击