은 Identity 기능을 사용하여 읽기 라이브러리 코드가 약간 쉬워집니다. Enumerable#any 방법을 가지고 : 그것은 배열의 요소 중 하나가 부울 컨텍스트에 해당하는 경우 사용자가 점검 할 수있게
any: function(iterator, context) {
iterator = iterator || Prototype.K;
var result = false;
this.each(function(value, index) {
if (result = !!iterator.call(context, value, index))
throw $break;
});
return result;
},
.
$A([true, false, true]).any() == true
그러나 그것은 또한 당신이 진실을 점검하기 전에 각 요소를 처리 할 수 있습니다 :과 같이,
이제
$A([1,2,3,4]).any(function(e) { return e > 2; }) == true
어떤 기능의 두 가지 버전을 작성해야 식별 기능이없는 하나 당신이 사전 처리한다면, 하나도하지 않으면.
any_no_process: function(iterator, context) {
var result = false;
this.each(function(value, index) {
if (value)
throw $break;
});
return result;
},
any_process: function(iterator, context) {
return this.map(iterator).any();
},