using setTimeout when using prototype

J

James Black

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.
 
N

Nathan White

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

}

processForm.prototype.submitForm2=function() {
}

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

Lasse Reichstein Nielsen

James Black said:
I have an object, and I define the following:
var processForm=new Object();

No need to assign an object to the variable when you overwrite
it immediatly afterwards:
processForm=function(inservleturl) {
this.inservleturl = inservleturl;
this.submitForm();
}

processForm.prototype.submitForm2=function() {

Should this have been "submitStep2"?
}

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

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.
How can the submitForm function's setTimeout call submitStep2?

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

/L
 
T

Thomas 'PointedEars' Lahn

Lasse said:
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.

Say property instead and you are correct.
Try:
var self = this;
setTimeout(function(){self.submitStep2();}, 20);
^^^^^
Are you sure?


PointedEars
 
L

Lasse Reichstein Nielsen

Thomas 'PointedEars' Lahn said:
Lasse Reichstein Nielsen wrote:

Say property instead and you are correct.

Not understood. I assumed that "submitForm2" should have been
"submitStep2". It was a property of processForm.prototype, but it was
not a variable anywhere.
^^^^^
Are you sure?

.... 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
 
T

Thomas 'PointedEars' Lahn

Lasse said:
Not understood. I assumed that "submitForm2" should have been
"submitStep2". It was a property of processForm.prototype, but it was
not a variable anywhere.

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.
... 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.

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


PointedEars
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Wed, 1 Feb
2006 18:10:51 remote, seen in Thomas
'PointedEars' Lahn said:
Correct. Sorry, I overlooked the first line, probably because it was late.

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.
 
J

James Black

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top