Hi,
I'm currently building a parser class in JS and I have a question
about variables. I retrieve XML data and then process it. After that, I
process a result array (mydataarray). It looks like this :
function MyClass()
{
var mydataarray = [];
this.processXML node = processXMLnode;
this.processxml Doc = processxmlDoc;
this.processreq uest = processrequest;
function processXMLnode( marker) {
// ADD SOMETHING TO mydataarray
}
function processxmlDoc(x mlDoc) {
var markers =
xmlDoc.document Element.getElem entsByTagName(" data");
mydataarray = [];
for (var i = 0; i < markers.length; i++) {
processXMLnode( markers[i]);
}
// PROCESS mydataarray
}
function processrequest( url, async) {
var request = XMLHttpRequest. create();
request.open("G ET", url, async);
if (async) {
request.onready statechange = function() {
if (request.readyS tate == 4) {
processxmlDoc(r equest.response XML);
}
}
request.send(nu ll);
}
else
{
request.send(nu ll);
processxmlDoc(r equest.response XML);
}
}
}
I'm not a JS expert, does processxmlDoc will be executed from the same
thread (or execution context) every time? Does processxmlDoc is called
only when nothing else is executing? Otherwise, how can I use a safe
array?
Cheers
Gabriel
I'm currently building a parser class in JS and I have a question
about variables. I retrieve XML data and then process it. After that, I
process a result array (mydataarray). It looks like this :
function MyClass()
{
var mydataarray = [];
this.processXML node = processXMLnode;
this.processxml Doc = processxmlDoc;
this.processreq uest = processrequest;
function processXMLnode( marker) {
// ADD SOMETHING TO mydataarray
}
function processxmlDoc(x mlDoc) {
var markers =
xmlDoc.document Element.getElem entsByTagName(" data");
mydataarray = [];
for (var i = 0; i < markers.length; i++) {
processXMLnode( markers[i]);
}
// PROCESS mydataarray
}
function processrequest( url, async) {
var request = XMLHttpRequest. create();
request.open("G ET", url, async);
if (async) {
request.onready statechange = function() {
if (request.readyS tate == 4) {
processxmlDoc(r equest.response XML);
}
}
request.send(nu ll);
}
else
{
request.send(nu ll);
processxmlDoc(r equest.response XML);
}
}
}
I'm not a JS expert, does processxmlDoc will be executed from the same
thread (or execution context) every time? Does processxmlDoc is called
only when nothing else is executing? Otherwise, how can I use a safe
array?
Cheers
Gabriel
Comment