How to compare 2 elements with same getElementById(x)?

T

Thomas 'PointedEars' Lahn

Richard said:
[...]
Given that the next line of code calls a - push - method on whatever is
referred to by - vals[val] -, a safer test might be:-

if((vals[val])&(vals[val].push)){ ...

- as then the Array nature of the objects assigned as properties of the
object would be verified (assuming no prototype augmentation to provide
an inherited property of Object that was an Array, and no introduction
of - push - methods on other object types).

The test would fail with JavaScript < 1.2 (NN < 4), JScript < 5.5 (IE < 5.5)
and ECMAScript < 3. A more reliable test would be

if (vals[val] && vals[val].constructor == Array)
{
// ...
}

since that would only fail with JavaScript < 1.1 (NN < 3) and JScript < 2.0
(IE < 4.0).

Of course, for the above versions without native Array.prototype.push()
support, one could augment the prototype before (with all side-effects of
user-defined properties):

if (typeof Array.prototype.push == "undefined")
{
Array.prototype.push = function Array_push()
{
for (var i = 0, len = arguments.length; i < len; i++)
{
this[this.length] = arguments;
}
}
}


PointedEars
 
V

vadymus

Thank you all. I will try your suggestions when I get to my testing
area.
Happy holidays!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top