0

How to call a function via string within a class?

$.fn.myApp = function (options){
  function myFunc(){
    //do something
  }
  window["myFunc"](); //not working
  $.fn.myApp["myFunc"](); //not working
}
neosmart
  • 103
  • 8

2 Answers2

1

I found a solution, maybe that helps anybody else as well!

$.fn.myApp = function (options){
  $.fn.myApp.myFunc = function(){
    //do something
  }
  $.fn.myApp["myFunc"](); //working
}
neosmart
  • 103
  • 8
0

Take a look at this code: you need to expose the method in order to call it form outside that function: http://jsbin.com/aXuloFE/1/

ravenlp
  • 394
  • 1
  • 5