OO JS Object在IE8中不支持此属性或方法

时间:2014-02-21 12:51:53

标签: javascript oop internet-explorer-8

我目前遇到一些与OOP JavaScript相关的IE8错误。在IE9 +,chrome,firefox等中一切正常。我也尝试在stackoverflow上找到类似的问题,但失败了。

代码:

$(function(){
    // Notification
    OPD_Notification = function( selector ) {
        this.selector = selector;
    }

    OPD_Notification.prototype.setText = function( text ) {
        $(this.selector).find('.container').text(text);
    };

    OPD_Notification.prototype.setStatus = function( status ) {
        $(this.selector).addClass(status);
    }

    OPD_Notification.prototype.removeStatus = function( status ) {
        $(this.selector).removeClass(status);
    }

    OPD_Notification.prototype.show = function() {
        $(this.selector).slideDown(200);
    };

    OPD_Notification.prototype.hide = function() {
        $(this.selector).slideUp(200);
    };

    // Notification
    notification = new OPD_Notification('#notification');
});

问题: 当我尝试执行以下操作时,IE8会向我抛出错误Object doesn't support this property or methodnotification = new OPD_Notification('#notification');我想这可能与jQuery有关,但不是很确定。

好像我运行下面的代码,它在IE8中运行良好。

function Rabbit( line ) {
    this.line = line;
}

Rabbit.prototype.speak = function() {
    alert(this.line);
};

rbt = new Rabbit("Well, now you're asking me.");
rbt.speak();

关于我做错事的任何提示都会有所帮助。感谢。

JSFiddle

1 个答案:

答案 0 :(得分:0)

不知道怎么做,也不知道为什么。但我已将notification = new OPD_Notification('#notification');更改为prefixNotification = new OPD_Notification('#notification');并开始工作。