🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: chile.comp.programacion
Article #3

Re: Javascript: setTimeout() dentro de un objeto

#3
From: Benjamin Porter
Date: Tue, 04 Aug 2009 21:34
58 lines
2814 bytes
"Marious" <sinspam@tampocoexiste.ivn.cl> escribi� en el mensaje 
news:h5a9b5$is5$1@news.nivel5.cl...
> Tengo un objeto con dos funciones, una que crea un div, y
> otra que le aumenta el alto de 5 en 5 hasta llegar a 20
> (osea 4 veces).-
>
> objeto =
> {
> sumar: 5,
> pasos: 4,
> crearDiv: function()
> {
> this.elDiv = document.createElement('div');
> // aqu� se pone cualquier codigo para
> // darle estilos y a�adirlo a alg�n otro elemento
> },
> agrandarDiv: function()
> {
> if (!this.tamanno) this.tamanno = 0;
> this.pasos   -= 4;
> this.tamanno += this.sumar;
> this.elDiv.style.height = this.tamanno+'px';
> if (this.pasos != 0) setTimeout(this.agrandarDiv,100);
> // Ah� est� el drama ?
> }
> }
>
> Si llamo a la funci�n de agrandarDiv inmediatamente, funciona a la
> perfecci�n... no as� con un "setTimeout".
>
> Necesito usar setTimeout porque quiero una demora de 100ms entre cada
> suma para que as� se vea aparecer el div.
>
> El problema es que al hacer un setTimeout, la funci�n no se llamar�
> en el mismo contexto, sino fuera, y "this" perder� su valor original...
> osea, la referencia al objeto de la funci�n.
>
> Lo que busco, es una soluci�n para poder realizarlo,
> pero con las siguientes reglas.
>
> No utilizar el nombre estatico del objeto.
> No utilizar ID para referirse al div.
> No registrar una variable global que haga referencia al objeto.
> Que me permita cambiar el nombre del objeto y no haya que
> tocar el codigo de este.
>
> A ver si a alguien se le ocurre y me puede ayudar...
> Thx~


�window.setTimeout?


-- 
Salu2
_____________________
Benjamin Porter 
Technical Details
Message-ID: <h5a9ga$p0u$1@jagger.tie.cl>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!news-xfer.nntp.sonic.net!news.kjsl.com!news.nivel5.cl!news.tie.cl!not-for-mail
References: <h5a9b5$is5$1@news.nivel5.cl>

Show Full Headers
Complete Article Headers
X-Google-Thread: 5075a5d0e4,6a8c59e449cbbab
X-Google-Attributes: gid5075a5d0e4,public,usenet
X-Google-NewGroupId: yes
X-Google-Language: SPANISH,ASCII
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!news-xfer.nntp.sonic.net!news.kjsl.com!news.nivel5.cl!news.tie.cl!not-for-mail
From: "Benjamin Porter" <benja.porter@gmail.com>
Newsgroups: chile.comp.programacion,chile.comp.internet,chile.comp.www
Subject: Re: Javascript: setTimeout() dentro de un objeto
Date: Tue, 4 Aug 2009 17:34:02 -0400
Organization: Telefonica Internet Empresa
Lines: 60
Message-ID: <h5a9ga$p0u$1@jagger.tie.cl>
References: <h5a9b5$is5$1@news.nivel5.cl>
Reply-To: "Benjamin Porter" <benja.porter@gmail.com>
NNTP-Posting-Host: 74-111-246-201.adsl.terra.cl
X-Trace: jagger.tie.cl 1249421642 25630 201.246.111.74 (4 Aug 2009 21:34:02 GMT)
X-Complaints-To: news@jagger.tie.cl
NNTP-Posting-Date: Tue, 4 Aug 2009 21:34:02 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
X-RFC2646: Format=Flowed; Response