include() 指定された値があるか
<script>
Array.prototype._each = function(iterator){
for(var i=0, l=this.length; i<l; i++){
iterator(this[i]);
}
};
Array.prototype.each = function(iterator){
var index = 0;
try{
this._each(function(v){
iterator(v, index++);
});
} catch(e){
if(e != $break) throw e;
}
};
Array.prototype.include = function(obj){
var found = false;
this.each(function(v, k){
if(v == obj){
found = true;
throw $break;
}
});
return found;
};
var $break = {};
var kekka = [1, 2, 3, 4].include(3);
console.log(kekka);
</script>