简体   繁体   中英

Uncaught TypeError: Object function ()

I wrote the following functions. At run time the browser complains about uncaught TypeError ...has no method 'init'. What's wrong of my code?

function build_results_grid (response) {

        // build grid
        grid_ui.init();

    } // build the results grid

    var grid_ui = function () {

        return {
            init: function () {
               //build_grid();
            }
      }; // return
    } 

You assigned grid_ui to a function, without calling it.

Change that to

var grid_ui = (function() { ... })();

since a call to grid_ui is necessary to return the function with init inside, you need

    grid_ui().init();

Since grid_ui must be called. Or you can make grid_ui be the return of the call, as SLaks did

EDIT - I misread your braces, if you noticed the question I had here before you can disregard it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM