0

I am using reveal module pattern but can't call the method.

$(function () {   
       $(document).on("click", '.EditBill', function () {

        editModule.EditBill(this);
    }); 
});

var editModule = (function () {

    function EditBill(object) {
        var itemId = $(object).data('itemid');

        loader.show();
        $.ajax({
            url: 'Bill/Edit',
            data: { id: ItemId },
            success: function (data) {
                loader.hide();
                $('#ModelPopup').empty();
                $('#ModelPopup').html(data);
                $(function () {
                    $('#editModal').modal();     
                });
            }
        });
    }

    return 
    {
        EditBill: EditBill
    } 
    }());

When I debug in Edge, I click the button ('.EditBill'), the message is

> SCRIPT5007: Unable to get property 'EditBill' of undefined or null

Thanks for Shyju, the answer is return and the first curly brace '{', should be on the same line! It works now. I don't understand why I have to follow this syntas, but it works.

DennisL
  • 293
  • 1
  • 3
  • 12
  • Change the return part to a 3 line statement.`return { EditBill: EditBill }` and see what happens. First line should be `return {` and second line should be `EditBill: EditBill` and third `}` – Shyju Dec 29 '17 at 01:41
  • What is your `editModule` trying to accomplish, as an immediately invoked function that's below where you want to use it? `editModule` will be hoisted up and be `undefined` until you hit the bottom of your code, which never happens because it fails when it tries to use a method from `editModule` – Andrew Dec 29 '17 at 01:42
  • @DennisL I did not mean to edit the question ! i meant to edit the code in your page and try ( It worked for me in chrome. (although i get a different error about `loader` not being defined) – Shyju Dec 29 '17 at 01:50
  • @Shyju, thanks for your advise. The codes in my project has the correct format and it doesn't work, the post didn't have the correct format, that's the reason I edit my post. – DennisL Dec 29 '17 at 01:51
  • @Shyju, sorry I know what you mean now, the first { should be the same line as return, it works now! Thanks for your advise! – DennisL Dec 29 '17 at 01:54
  • Totally works for me. See the jsbin http://jsbin.com/nowebax/edit?html,js,console,output – Shyju Dec 29 '17 at 01:56
  • That is what's called being a "victim of automatic semi-colon insertion". - https://stackoverflow.com/questions/2846283. – Roamer-1888 Dec 29 '17 at 02:19
  • @Roamer-1888, thanks very much! :) – DennisL Dec 29 '17 at 02:34

0 Answers0