Click here to Skip to main content
15,942,449 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Alert: Stupid Question

I have task.js file, with a class called Task in it, using the revealing modular pattern.

i'm working on a MVC application, and i've checked the HTML Jquery library gets loaded before my JS script, the following code for the contents of my JS file is below.

the file shows as loaded in the HTML (last), and Network:Scripts in developer tools.

The app works if i use the literal pattern for the class.
Why will it not work with the module pattern? I've used this pattern all the time and not had this problem, what am i doing wrong?


"Uncaught TypeError: Cannot read property 'init' of undefined"


var Task = (function () {

    var initialize = function () {
    var postFilter = function () {
        var postData = {
            UserID: $('#user_select').val,
            TaskTypeID: $('#taskTypeSelect').val,
            TaskStatusID: S('#status_select').val,
            PriorityID: $('#priority_select').val

            url: "/Tasks/_AllTaskView",
            data: postData,
            success: function (response) {


    var bindEvents = function () {
        $('#submit_filter').on('click', postFilter);

        init : initialize



$(document).ready(function () {
Updated 11-Dec-14 1:25am

1 solution

You're going to scream when I tell you.

It's bad line breaking.

At the end of the anonymous function that creates Task you say;

return //that's it, javascript will return and not read the next statement
    init: initialize

All you have to do is make it clear that more is to come by placing the opening bracked after the return on the same line;

return { 
 init: initialize

If you use a helper like jshint/jslint this will be caught by them and they will point it out.

Happy coding
Share this answer

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