I have the following function, by which I am attempting to set the value of the variable theString.
readStringFromFile is an asynchronous call that reads a text file and returns the first line of text within it.
This line of text is being retrieved and assigned to variable v. The alert box displays the line of text ok, as required.
However - 'return v' does not assign the value of v to theString (I guess because they are in different scopes?).
My question is: how can I adjust the code so that theString is assigned the value (v) that is retrieved from the asynchronous call?
There is a reason (not relevant here) why I have to wrap the asynchronous call inside the function that receives the id parameter, so I can't change that aspect.
I am new to jQuery so there may be basic errors here that need correction.
theString = function(id)
{
self.readStringFromFile("<path>/myFile").then
(
function(v)
{
alert(v);
return v;
}
)
}