Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyone,

I know how to use requireJS but I didn't use with Javascript oop technical. When I tried as the following, I am getting error which is
JavaScript
Uncaught TypeError: Cannot read property 'myClass' of undefined
. how to fix this error?

note :in my project, classes using the functions of each other.

thanks in advance.



purchase.js file:

JavaScript
define(["credits"], function(credits) {

      return {
        myClass: class{

            constructor()
            {
                this.try = new credits.try();
            }

            write(){
                console.log("Yes I did!");
                this.try.ert();
            }}
    }

});


credits.js file:

JavaScript
define(["purchase"],function(purchase) {

    return {
        try : class{
            constructor()
            {
                this.myClass =new purchase.myClass();
            }
           otherWrite(){
               this.myClass.write();
            }
           ert(){
                console.log("I am credit");
            }

        }
    }
});


What I have tried:

main.js file:

JavaScript
require(["purchase", "credits"],function(purchase, credits){

    var x = new purchase.myClass();
    x.write();

});
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900