0

I have the simple code:

<script type="text/javascript">

var dataFromBrowser;
var dataForStore = [];

var callServerOwnerId = { 
  callback:callbackFunction, 
  arg: dataFromBrowser 
};
// call to DWR function - from Java
AssetScreener.getEntityOwnerIds(callServerOwnerId);


function callbackFunction(dataFromServer, arg1) {
 // yes, I see what I need
 alert(dataFromServer);
 return dataForStore[0] = dataFromServer[0];

}



console.log(dataForStore);

The problem is that I need to retrieve data from my callbackFunction and set data to dataForStore ?

1
  • You don't need the "return", just dataForStore[0] = dataFromServer[0] Commented Nov 19, 2012 at 21:50

2 Answers 2

2

In javascript setting a global variable is as simple as ommitting the var keyword.

For example:

 var someVar = 5

 function foo(){
      someVar = someVar + 1;
 }   

Will produce undefined while

 someVar = 5;

 function foo(){

      someVar = someVar+1;
 }

Will produce 6. Note that generally speaking (there are of course exceptions), if you're using global variables you're doing it wrong.

Sign up to request clarification or add additional context in comments.

Comments

1

Remove the var before dataForStore , and it will become a global variable.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.