Question

I'm trying to use a Namespace in two different files.

First file:

        $(document).ready(function () {
               var App= window.App || {};

               App.Form = can.Control.extend({... });
               window.App = App;
        });

Second file:

        $(document).ready(function () {

               var App2 = window.App2 || {};

               App2.Form = can.Control({ 
               new App.Form();
               });

               window.App2 = App2;
        }); 

But I keep getting this error:

Uncaught TypeError: undefined is not a function.

What am I doing wrong?

Was it helpful?

Solution

Try this in your second file

;(function(global) {

    var App = window.App || {}


    $(document).ready(function () {

           var App2 = window.App2 || {};

           App2.Form = can.Control({ 
           new App.Form();
           });

           window.App2 = App2;
    }); 

})(window);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top