1

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();
       },
   };
}
1
  • might want to move that "Use strict" above the $(document). ready. if you place it at the top of your script you dont need to call it in each function Commented Mar 14, 2015 at 11:34

2 Answers 2

2

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

var Reports = function () { ... }()
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks mate! I had not noticed that in the others scripts!!
-1

$(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
   });
});

2 Comments

You defined a function constructor in report.js
thanks your help mate, I choose the other one just because is less code... ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.