Foros del Web » Programando para Internet » Javascript »

Duda con IF

Estas en el tema de Duda con IF en el foro de Javascript en Foros del Web. Estaba viendo el código para agregarle la función each al objeto Array Código: Array.prototype.each = function(fun) { if(typeof fun != 'function') { throw new TypeError(); ...
  #1 (permalink)  
Antiguo 03/01/2009, 02:30
 
Fecha de Ingreso: marzo-2008
Mensajes: 166
Antigüedad: 16 años, 1 mes
Puntos: 5
Duda con IF

Estaba viendo el código para agregarle la función each al objeto Array

Código:
Array.prototype.each = function(fun)
{
	if(typeof fun != 'function') {
		throw new TypeError();
	}
	
	for(var i=0; i < this.length; i++) {
		if(i in this) {
			fun.call(arguments[1], i, this[i]);
		}
	}
	return this;
};
Pero no logro entender que comprueba este if
Código:
if(i in this) {
¿Alguien me puede ayudar?
  #2 (permalink)  
Antiguo 03/01/2009, 05:17
venkman
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Duda con IF

Ese if comprueba lo que dice, "si i está en this". O dicho de otro modo, si es realmente un elemento del array.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:34.