简体   繁体   中英

OO JS Object doesn't support this property or method in IE8

I am currently experiencing some IE8 bugs related to OOP JavaScript. Everything works fine in IE9+, chrome, firefox etc. I have also tried to find similar issues on stackoverflow, but failed.

Code:

$(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');
});

Problem: IE8 throws me an error Object doesn't support this property or method when I try to do following: notification = new OPD_Notification('#notification'); I guess it might be something to do with jQuery, but not really sure.

As if I run code bellow, it works fine in 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();

Any tips on what I am doing wrong, would help a lot. Thanks.

JSFiddle

Don't know how, and don't know why. But I've changed notification = new OPD_Notification('#notification'); to prefixNotification = new OPD_Notification('#notification'); and it started working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM