prototype.js分析 Enumerable

全ての基本は _each() each()

<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;
	this._each(function(v){
		iterator(v, index++);
	});
};

"hoge,moge,foo,bar".split(',').each(function(v, k){
	console.log(k + ":" + v);
});
</script>