Connecting Tech Pros Worldwide Help | Site Map

using setTimeout when using prototype

  #1  
Old January 31st, 2006, 04:55 PM
James Black
Guest
 
Posts: n/a
I have an object, and I define the following:
var processForm=new Object();

processForm=function(inservleturl) {
this.inservleturl = inservleturl;
this.submitForm();
}

processForm.prototype.submitForm2=function() {
}

processForm.prototype.submitForm=function() {
setTimeout("submitStep2()", 20);
}


How can the submitForm function's setTimeout call submitStep2?

Thank you.

  #2  
Old January 31st, 2006, 07:35 PM
Nathan White
Guest
 
Posts: n/a

re: using setTimeout when using prototype


processForm=function(inservleturl) {
this.inservleturl = inservleturl;
this.submitForm();

}

processForm.prototype.submitForm2=function() {
}

processForm.prototype.submitForm=function() {
var self = this;
setTimeout(
function(){ self.submitForm2();}
, 20);
}

  #3  
Old February 1st, 2006, 01:15 AM
Lasse Reichstein Nielsen
Guest
 
Posts: n/a

re: using setTimeout when using prototype


"James Black" <planiturthian@gmail.com> writes:
[color=blue]
> I have an object, and I define the following:
> var processForm=new Object();[/color]

No need to assign an object to the variable when you overwrite
it immediatly afterwards:
[color=blue]
> processForm=function(inservleturl) {
> this.inservleturl = inservleturl;
> this.submitForm();
> }
>
> processForm.prototype.submitForm2=function() {[/color]

Should this have been "submitStep2"?
[color=blue]
> }
>
> processForm.prototype.submitForm=function() {
> setTimeout("submitStep2()", 20);[/color]

WHen the first argument to setTimeout is a string, then it
is parsed and executed as a program in the global context.
Even if it wasn't, "submitStep2" is not a variable in
any scope.
[color=blue]
> How can the submitForm function's setTimeout call submitStep2?[/color]

Try:
var self = this;
setTimeout(function(){self.submitStep2();}, 20);

/L
--
Lasse Reichstein Nielsen - lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
  #4  
Old February 1st, 2006, 02:15 AM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a

re: using setTimeout when using prototype


Lasse Reichstein Nielsen wrote:
[color=blue]
> "James Black" <planiturthian@gmail.com> writes:[color=green]
>> processForm.prototype.submitForm=function() {
>> setTimeout("submitStep2()", 20);[/color]
>
> WHen the first argument to setTimeout is a string, then it
> is parsed and executed as a program in the global context.
> Even if it wasn't, "submitStep2" is not a variable in
> any scope.[/color]

Say property instead and you are correct.
[color=blue][color=green]
>> How can the submitForm function's setTimeout call submitStep2?[/color]
>
> Try:
> var self = this;
> setTimeout(function(){self.submitStep2();}, 20);[/color]
^^^^^
Are you sure?


PointedEars
  #5  
Old February 1st, 2006, 04:55 PM
Lasse Reichstein Nielsen
Guest
 
Posts: n/a

re: using setTimeout when using prototype


Thomas 'PointedEars' Lahn <PointedEars@web.de> writes:
[color=blue]
> Lasse Reichstein Nielsen wrote:[/color]
[color=blue][color=green]
>> Even if it wasn't, "submitStep2" is not a variable in
>> any scope.[/color]
>
> Say property instead and you are correct.[/color]

Not understood. I assumed that "submitForm2" should have been
"submitStep2". It was a property of processForm.prototype, but it was
not a variable anywhere.
[color=blue][color=green][color=darkred]
>>> How can the submitForm function's setTimeout call submitStep2?[/color]
>>
>> Try:
>> var self = this;
>> setTimeout(function(){self.submitStep2();}, 20);[/color]
> ^^^^^
> Are you sure?[/color]

.... checking ... rechecking ... yes, I'm sure.

Perhaps it would be more readable to Rename the variable "self" to
"thisProcessFrom", but that would not change the meaning of the
program.

/L
--
Lasse Reichstein Nielsen - lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
  #6  
Old February 1st, 2006, 05:25 PM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a

re: using setTimeout when using prototype


Lasse Reichstein Nielsen wrote:
[color=blue]
> Thomas 'PointedEars' Lahn <PointedEars@web.de> writes:[color=green]
>> Lasse Reichstein Nielsen wrote:[color=darkred]
>>> Even if it wasn't, "submitStep2" is not a variable in
>>> any scope.[/color]
>> Say property instead and you are correct.[/color]
>
> Not understood. I assumed that "submitForm2" should have been
> "submitStep2". It was a property of processForm.prototype, but it was
> not a variable anywhere.[/color]

What I meant was that a method reference does not need to be a
identifier of a variable for the method to be possible to be called.
[color=blue][color=green][color=darkred]
>>>> How can the submitForm function's setTimeout call submitStep2?
>>> Try:
>>> var self = this;
>>> setTimeout(function(){self.submitStep2();}, 20);[/color]
>> ^^^^^
>> Are you sure?[/color]
>
> ... checking ... rechecking ... yes, I'm sure.[/color]

:)
[color=blue]
> Perhaps it would be more readable to Rename the variable "self" to
> "thisProcessFrom", but that would not change the meaning of the
> program.[/color]

Correct. Sorry, I overlooked the first line, probably because it was late.


PointedEars
  #7  
Old February 2nd, 2006, 07:05 PM
Dr John Stockton
Guest
 
Posts: n/a

re: using setTimeout when using prototype


JRS: In article <2322516.Y3jH0WxOQy@PointedEars.de>, dated Wed, 1 Feb
2006 18:10:51 remote, seen in news:comp.lang.javascript, Thomas
'PointedEars' Lahn <PointedEars@web.de> posted :[color=blue]
>
>Correct. Sorry, I overlooked the first line, probably because it was late.
>[/color]

You've already been told to pay more attention to what you write.

Time-of-day is no excuse for carelessness.

Gaining a reputation for unreliability will not enhance your career
prospects.

Feeling that you must answer, even if in haste, is mere arrogance; you
are not indispensable.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME ©
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
  #8  
Old February 3rd, 2006, 03:25 AM
James Black
Guest
 
Posts: n/a

re: using setTimeout when using prototype


Thank you for the suggestion. I will try it in tomorrow and see what
happens.

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
to learn jQuery if already using prototype liketofindoutwhy answers 83 June 27th, 2008 08:10 PM
setTimeout in object methods using closures (old problem?) rain_c1@web.de answers 2 May 22nd, 2006 04:25 PM
Object this and setTimeout Telmo Costa answers 4 February 22nd, 2006 05:55 PM
passing values in a setTimeout function domeceo answers 3 July 20th, 2005 03:42 PM