0

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?

Glund
  • 507
  • 1
  • 5
  • 20

1 Answers1

1

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);
Paul Rad
  • 4,820
  • 1
  • 22
  • 23