15.4.4.17 Array.prototype.some(callbackfn[, thisArg])

2010-07-05

boolean Array.prototype.some(callbackfn:function[, thisArg:mixed=undefined]) throws TypeError

Call callbackfn with elements of this array. If the callback returns true so does some. Otherwise the next element is processed. If all elements are processed that way return false.

The callbackfn should have this fingerprint: boolean|mixed function(element:mixed, index:int, object:object), where the return value is coerced to boolean.

The callback is not called for elements that do not exist ([[HasProperty]]).

The thisArg parameter will be used as the context (this) for callbackfn, undefined if not supplied.

The some function does not alter the array. The callback is allowed to do this.

The some function determines the amount of elements to process at the beginning. The used value is the value the array has at the time of accessing that specific index (even if it was changed by callbackfn). Deleted properties are skipped.

If the array is empty, some returns false.

The this value is coerced into an object, thisArg (if supplied) is not changed.

Array.protype.some.length = 1

Code: (Meta Ecma)
Array.prototype.some = function(callbackfn, thisArg){
var O = ToObject(this);
var lenValue = O.[[Get]]("length");
var len = ToUint32(lenValue);
if (!IsCallable(callbackfn)) throw TypeError;
if (arguments.length >= 2) var T = thisArg;
else T = undefined; // not required ;)
var k = 0;
while (k < len) {
var Pk = ToString(k);
var kPresent = O.[[HasProperty]](Pk);
if (kPresent) {
var kValue = O.[[Get]](Pk);
var testResult = callbackfn.[[Call]](T, [kValue, k, O]);
if (ToBoolean(testResult)) return true;
}
++k;
}
return false;
}