IE8 undefined class

I stupidly decided to support IE8 on my latest project, which will undoubtedly go down in history as the dumbest idea of ​​my life.

So the most fundamental problem I am facing is that my main class variable is undefined. I mean, I have a prototype created in the general.js file that looks something like this:

var generalClass;

// jQuery Object
var $ = jQuery; 

$(document).ready(function() {

    // A general class for a general file.
    generalClass = function() {

    }

    generalClass.prototype = {

    }


    new generalClass();     


});

      

So the generalClass variable is populated by my prototype / etc. Then I include this at the beginning of my document, and later I call a function in that generalClass for something else, something like this:

<script type="text/javascript" src="general.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $.ajax({
        type: 'POST', 
        url: ..., 
        data: {

        }, 
        success : function(data) {
            // CALL MY FUNCTION:    
            generalClass.prototype.myFunction();

        }


    }
});
</script>

      

In every browser from IE9 to Chrome, this works. In IE8 this doesn't work and generalClass is undefined. Why is he doing this to me?

+3


source to share


1 answer


I'm not sure where you found this pattern, but it should be something like this:

var generalClass;

// jQuery Object
//var $ = jQuery;  <-- makes no sense $ should be jQuery already

$(document).ready(function() {

    function GeneralClass() {}
    GeneralClass.prototype = {
        myFunction: function () {
            alert("x");
        }
    };

    generalClass = new GeneralClass();

});

      



and when you call it

generalClass.myFunction();

      

+3


source







All Articles