Connecting Tech Pros Worldwide Forums | Help | Site Map

using setTimeout when using prototype

James Black
Guest
 
Posts: n/a
#1: Jan 31 '06
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.


Nathan White
Guest
 
Posts: n/a
#2: Jan 31 '06

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);
}

Lasse Reichstein Nielsen
Guest
 
Posts: n/a
#3: Feb 1 '06

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.'
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#4: Feb 1 '06

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
Lasse Reichstein Nielsen
Guest
 
Posts: n/a
#5: Feb 1 '06

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.'
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#6: Feb 1 '06

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
Dr John Stockton
Guest
 
Posts: n/a
#7: Feb 2 '06

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.
James Black
Guest
 
Posts: n/a
#8: Feb 3 '06

re: using setTimeout when using prototype


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

Closed Thread