Connecting Tech Pros Worldwide Help | Site Map

using setTimeout when using prototype

 
LinkBack Thread Tools Search this Thread
  #1  
Old January 31st, 2006, 03:55 PM
James Black
Guest
 
Posts: n/a
Default using setTimeout when using prototype

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, 06:35 PM
Nathan White
Guest
 
Posts: n/a
Default 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, 12:15 AM
Lasse Reichstein Nielsen
Guest
 
Posts: n/a
Default 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, 01:15 AM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
Default 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, 03:55 PM
Lasse Reichstein Nielsen
Guest
 
Posts: n/a
Default 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, 04:25 PM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
Default 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, 06:05 PM
Dr John Stockton
Guest
 
Posts: n/a
Default 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, 02:25 AM
James Black
Guest
 
Posts: n/a
Default Re: using setTimeout when using prototype

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

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.