Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery function not returning

(function($){

    $.a.b  = {

        title: "ABC",

        init: function (id) {
                 /* do something here */
                  return id+'a';

              }




    };

})(jQuery);

When I try to call $.a.b.init('t'); it does not work, I mean it does not return as expected. Any suggestions?

The problem is not that $.a.b.init('t') is not working. Problem is that it returns the code of the whole function instead of returning say a string.

Thank you for your time.

like image 677
Alec Smart Avatar asked Sep 02 '26 05:09

Alec Smart


1 Answers

try

$.a = [];
$.a.b  = { ... }

or even better:

$.a = {b: {
     title: "",
     init: ...
}};

When using $.a.b a is undefined, so you cannot add to it.

like image 100
Kobi Avatar answered Sep 03 '26 18:09

Kobi