node.js - parameter of the anonymous function need to be modified and stored in a global variable in javascript -


how value returned anonymous function used parameter in javascript function?

in following method call registerdevice, want "status" value of anonymous function outside function scope.

pushnotification.registerdevice({alert:true, badge:true, sound:true}, function(status) {   // if successful status object looks this:   // {"type":"7","pushbadge":"1","pushsound":"1","enabled":"1","devicetoken":"blablahblah","pushalert":"1"}   console.warn('registerdevice:%o', status);     }); 

assuming supplied function called asynchronously, shouldn't using return value outside of scope because won't know @ point function called.

you'd need make further processing start within callback function, status variable either in scope, or passed directly later functions, i.e.

pushnotification.registerdevice({alert:true, badge:true, sound:true}, function(status) {     console.warn('registerdevice:%o', status);      // stuff "status"     func1(status);      // put in global if must     global.status = status; });  // processing continues here immediately, can't access // "status" here because won't have been set yet.  console.log(global.status);  //  -- undefined 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -