Access page.binding content from another function


#1

I am asking this question to know what is the best practices as it relates to global data. I want to access data properties from a navigationContext in another function. I have this:

function loaded(args) {
 var page = args.object;
 page.bindingContext = page.navigationContext;
 global.state = page.navigationContext;
}

function anotherFunctionWhichNeedBindingContext(){
   console.log(global.state.someProperty);
}

exports.navigatingTo = navigatingTo;

is this the proper way to get the navigationContext in another function?


#2

I just store the page and binding context in a variable instead of mucking up the global scope. Is this what you mean?

var page = null
var bindingContext = null;

function loaded(args) {
 page = args.object;
 bindingContext = page.navigationContext;
 page.bindingContext = bindingContext;
}

function anotherFunctionWhichNeedBindingContext(){
   //do whatever with "page" or "bindingContext"
}

exports.navigatingTo = navigatingTo;

#3

Thank you for this. This make more sense.