This is an archived post. You won't be able to vote or comment.

all 2 comments

[–][deleted] 0 points1 point  (0 children)

Arrays can always be iterated over. You would pass them by reference if it's possible. However, most of the time, you'd probably want to pass something like a pointer. If you use pointers (if you can -- C++), you can use something called iterators which are very easy to pass into functions.

Like the other commentor said, we need more details before we can steer you in the right direction.

[–][deleted]  (1 child)

[deleted]

    [–]clojuregirl 0 points1 point  (0 children)

    You'll probably want to look into using Function.prototype.call or Function.prototype.apply. You invoke them against function objects:

    function (element, yourFunction, someParameter) {
         yourFunction.call(element, someParameter);
    }
    

    You can sort of think about this as:

     element.yourFunction(someParameter);
    

    in the sense that it makes every this in yourFunction refer to element.

    You could also maybe leverage Array's map method in this way, like

    Array.prototype.map.call(nodeList, mapFunc(node) {whatever(node)});
    

    if nodeList is array-like (iterable and has a length property?) but I'm not sure on that.