0

Well, I am trying to call a function that has object & method in 1 file to another file.

File 1 --
    var a ={
            resizeGrid : function(){
            //this manipulates the height & width of a grid
                                   }
           }
File 2 --
    var b ={
            manipulateGrid: function(){
            $('#containerGrid_0').a('resizeGrid');
                                      }
           }

I am trying to convert the older version of Jquery to the latest version ie. 1.7 to 2.2.2 using migrate plugin. Facing this issue " cannot call methods on A prior to initialization; attempted to call method 'resizeGrid'"

Tried some solution like below but didn't work. $('#containerGrid_0').a().a('resizeGrid');

For information look jquery ui Dialog: cannot call methods on dialog prior to initialization

1 Answers1

0

Based on what you've provided, I can't tell exactly what your functions are doing, or how you are using them. But here is an example of how to initialize them.

You can play with it by clicking here: jsFiddle Example

$.fn.A = function(sFunc){
    var agrid = {
      resizegrid:function(ele){
        ele.append('<div>Hello</div>')
      }
    }
  agrid[sFunc](this)
};

$.fn.B = function(sFunc){
  var help = {
    checkResize:function(ele){
        ele.A('resizegrid')
    }
  }
  help[sFunc](this)
}

$('#btn').click(function(){
    $('body').B('checkResize')
})
jet_24
  • 598
  • 3
  • 8
  • Well, I am trying to call a function that has object & method in 1 file to another file. File 1 -- var a ={ resizeGrid : function(){ //this manipulates the height & width of a grid } } File 2 -- var b ={ manipulateGrid: function(){ $('#containerGrid_0').a('resizeGrid'); } } –  Oct 13 '21 at 05:39