Use array.indexOf native function when available. p=arno, r=ahocevar
git-svn-id: http://svn.openlayers.org/trunk/openlayers@9859 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
+10
-6
@@ -147,17 +147,21 @@ OpenLayers.Util.clearArray = function(array) {
|
|||||||
* obj - {Object}
|
* obj - {Object}
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* {Integer} The index at, which the object was found in the array.
|
* {Integer} The index at, which the first object was found in the array.
|
||||||
* If not found, returns -1.
|
* If not found, returns -1.
|
||||||
*/
|
*/
|
||||||
OpenLayers.Util.indexOf = function(array, obj) {
|
OpenLayers.Util.indexOf = function(array, obj) {
|
||||||
|
// use the build-in function if available.
|
||||||
for(var i=0, len=array.length; i<len; i++) {
|
if (typeof array.indexOf == "function") {
|
||||||
if (array[i] == obj) {
|
return array.indexOf(obj);
|
||||||
return i;
|
} else {
|
||||||
|
for (var i = 0, len = array.length; i < len; i++) {
|
||||||
|
if (array[i] == obj) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
return -1;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,14 @@
|
|||||||
"getImagesLocation()" );
|
"getImagesLocation()" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_Util_IndexOf(t) {
|
||||||
|
t.plan( 3 );
|
||||||
|
var array = new Array(1, "bar");
|
||||||
|
t.eq(OpenLayers.Util.indexOf(array, 1), 0);
|
||||||
|
t.eq(OpenLayers.Util.indexOf(array, "bar"), 1);
|
||||||
|
t.eq(OpenLayers.Util.indexOf(array, "foo"), -1);
|
||||||
|
}
|
||||||
|
|
||||||
function test_Util_Array(t) {
|
function test_Util_Array(t) {
|
||||||
t.plan( 2 );
|
t.plan( 2 );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user