How to properly assign JS event handler ?

Dear Bruno,


i have an "app.js" get loaded at index.html , 
it has this global var "app", 
var app = new MyFramework({
...
on: {
// each object key means same name event handler
pageInit: function (page) {
// do something on page init
},
popupOpen: function (popup) {
// do something on popup open
},
},
});

and in one of my child form which contain only <div>  , in my TMS WEBCORE  app , what can i
do to attach the event handler to the pageInit declared above during my TWebform create ?

 let say i wish to call the following JS code some where in my TMSWebcore ,

ASM
   app.on('pageInit', function (page) {
// do something on page init
});
END;

I am not sure where to put this , there are a few places i tried , but no success ,

1. before create TWebform , when i called the AFormClass.createNew , @onAfterCreate event
2. on the child's TwebForm , onCreate , onShow event 

can u please advice , how can i use TMS Webcore ASM block to call this page init  function?

from the code above , is there anything i can do to improve my JS code, 
i.e. how to declare the pageInit event handler in my App instance , that i can assign
in my Twebform later ?

Thanks,
Kalmen

If this app.js is included in the <HEAD> section, I would assume it is ready and available in the form's OnShow event.