I declare a function and assigned it to a Variable, inside the function was other functions. Normally, at first load of the page it loads the functions etc. When i used the variable in an ajax success callback, it says that the init() function is not a function.
This is my sample jquery function assigned to a variable called GRID:
var Grid = (function() {
function init( config ) { ... }
.
.
.
function addItems( $items ) { ... }
return { init: init, . . . addItems: addItems }
}
();
and i have a this ajax call
function updateItems{
.
.
.
.
jQuery.ajax({
type: 'get',
url: ajaxURL,
data: ajaxData,
dataType: 'json',
//Ajax call is successful
success: function ( response ) {
//Add new posts
Grid.init();
},
error: function () {
}
});
.
.
.
}
What's wrong with the codes? why would the Inspector returns an error that says Grid.init() is not a function? please help
Gridis not a function, nor an object, the function looks like it's an IIFE, otherwise why does it start with a parentheses, that returnsundefinedunless you explicitly return something, and you can't call that function later onvar Griddeclared in the same scope (containing function, or global scope) asupdateItems?var Gridis declared as global scope and alsoupdateItems. @billy what's wrong with my code?var Grid = (function() { ... })();<~~ note the calling braces