Carlos Diaz
Carlos Diaz

Reputation: 381

Why I can not initialize my variable in jQuery?

I'm freeze in my app. I want to create my own reports.js file using variables like a functions but I can not initialize it. I'm copying other ones already done in the template but I can't understand why mine is not working.

Here is the part where I call it into the head section.

$(document).ready(function(){
   "use strict";

   App.init(); // Init layout and core plugins
   Plugins.init(); // Init all plugins
   FormComponents.init(); // Init all form-specific plugins

   Reports.init();

   $('#StartDate').pickadate({
     formatSubmit: 'yyyy/mm/dd',
     hiddenName: true
   });
});

When I run the site, the console shows TypeError: Reports.init is not a function

Now I'm going to share the report.js file:

var Reports = function () {

   "use strict";

   var form = $('form').attr('id');
   alert(form);
   /* * * * * * * * * * * * * * *
    * Employee Clock-In Clock-Out
    * * * * * * * * * * * * * * */
   var EmployeeClocks = function(form) {
      // will do something
   }

   return {
       // main function to initiate reports
       init: function () {
          // EmployeeClocks();
       },
   };
}

Upvotes: 1

Views: 1812

Answers (2)

Caibao Kuang
Caibao Kuang

Reputation: 47

$(document).ready(function(){
   "use strict";

   App.init(); // Init layout and core plugins
   Plugins.init(); // Init all plugins
   FormComponents.init(); // Init all form-specific plugins

   // Reports.init();
   var reports = new Reports();
   reports.init();

   $('#StartDate').pickadate({
     formatSubmit: 'yyyy/mm/dd',
     hiddenName: true
   });
});

Upvotes: -1

ch271828n
ch271828n

Reputation: 17567

Add the (). Your Reports now is a function, not a class. But this function returns the thing you want.

var Reports = function () { ... }()

Upvotes: 2

Related Questions