Ace Spades
Ace Spades

Reputation: 39

JavaScript .call understanding

That is a code that is used as an addition to a URL for a XMLHttpRequest.What comes out in the url is:

http://something/something.aspx?QueryString_from_below

Array.prototype.slice.call(document.getElementsByName("radio"), 0)
    .find(function (el, pos, arr) {
        if (el.checked == true) {
            return el
        }
    }).id.replace("option", "") + "=" + document.getElementById("searchField").value;

So it puts the radios in an array,searches for the checked box,assembles the queryString but I cant figure out the part: Array.prototype.slice.call(document.getElementsByName("radio"), 0).Why call an argument 0 on an array?The output of that and this: document.getElementsByName("radio") is identical.

Upvotes: 0

Views: 51

Answers (1)

Slartibartfast
Slartibartfast

Reputation: 1583

The second argument represents the end position for slicing. So in your case, it'd extract only one element provided that document.getElementsByName("radio") has an index of 0. Reference MDN

Upvotes: 1

Related Questions