How to call method in Page instance


#1

Hello guys Im trying . to overide somethings in NS.
So I have a currentPage that Im on like this
let currentPage = page.frame.currentPage;
and on that page is for example profile.xml and I have associated file profile.js
is it possible I would want to call method defined in profile.js

in profile.js

function hello() {
console.log('hello');
}

and call it like in other file

 let currentPage = page.frame.currentPage;
currentPage.hello();

#2

I think you can fire that as an event. Listen for your custom event on page, trigger that even when you want to call the method.


#3

Sorry but I dont think I understand you clearly,
could you please explan or write some pseudo code ??


#4

For example when your page is loaded, add listeners. Remember, loaded event may be fired every time when you navigate back to the page so prevent adding redurant listeners.

page.on('hello', helloFunction [, context]);

When you want to call it, fire the event from page

currentPage.notify({ eventName: 'hello' });

Update: If you think events are not so flexible, try to attaching the function to the page object when it’s loaded.

page.hello = function(){...};

But I would recommend going with events only.


#5

Ok will try it, thank you very much