0

So i have the following code:

(function init_chart(){
    // body function
})();

it's working as expected. but when i tried to call the init_chart() from outside the function, console said it is undefined. then i tried to add the following line inside init_chart() function:

window['init_chart'] = this;

now console said init_chart is not a function.

Dariel Pratama
  • 1,607
  • 3
  • 18
  • 49

1 Answers1

2

You are creating a named function expression function, so basically the function is not defined on the global scope. The easiest way to get around it is to do the following:

function init_chart(){
    // body function
};
init_chart();
JCOC611
  • 19,111
  • 14
  • 69
  • 90