1
   var ret = [] 
             ,xresult = document.evaluate(exp, rootEl, null,
                         XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null)
             ,result = xresult.iterateNext();
   while (result) {
     ret[ret.length]= result;
     result = xresult.iterateNext();
   }

can anyone explain me what is the ret = [],..,... syntax? Initializing array?

1 Answer 1

2

You're right. This code:

var ret = [] 
             ,xresult = document.evaluate(exp, rootEl, null,
                         XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null)
             ,result = xresult.iterateNext();

Could be rewritten as:

var ret = [];
var xresult = document.evaluate(exp, rootEl, null,
                         XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null);
var result = xresult.iterateNext();

var foo = []; initializes foo as an empty array.

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

3 Comments

@artlung: yea but I don't see connection between empty ret, xresult and result... please elaborate more on this if you can. unless there is no connection and just short hand writing - one line initializing.
Right, there's no connection. So for example var var a = 1, b = 2, c = 3; is one way to write it, but I could do it like this too: var a = 1; var b = 2; var c = 3; ... using commas is merely coding style. Based on the code you posted, there's no link between ret, xresult and result.
Well, I shouldn't say "no link" -- the while loop your posted uses those three variables to populate the ret array. But the var line is just initialization.

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.