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