Global function outside page:init?

Hello,

I’m updating to v5 from an older version of the framework. In the old one I can run functions outside the page:init code, like this:

$$(document).on(‘page:init’, ‘.page[data-name=“home”]’, function (e) {
//some code here
myfunction();
});

function myfunction(){
//some code here
}

I noticed that now, I am only able to make myfunction() run if it is inside page:init, like this:

$$(document).on(‘page:init’, ‘.page[data-name=“home”]’, function (e) {
//some code here
myfunction();

function myfunction(){
//some code here
}
});

Is there a way I can call myfunction() without needing to put it inside page:init? I asked because myfunction() is global and I’d like it to be called anywhere on the app. If it is inside the home page code, other pages won’t be able to call it.

Thanks in advance! :slight_smile:

You just need to define the function as global if you want to call it everywhere, like:

window.myfuncion = function () {
  // ...
}

then it will be available everywhere