By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,590 Members | 663 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,590 IT Pros & Developers. It's quick & easy.

using setTimeout when using prototype

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

Jan 31 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
processForm=function(inservleturl) {
this.inservleturl = inservleturl;
this.submitForm();

}

processForm.prototype.submitForm2=function() {
}

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

Jan 31 '06 #2

P: n/a
"James Black" <pl***********@gmail.com> writes:
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Feb 1 '06 #3

P: n/a
Lasse Reichstein Nielsen wrote:
"James Black" <pl***********@gmail.com> writes:
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.


Say property instead and you are correct.
How can the submitForm function's setTimeout call submitStep2?


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

^^^^^
Are you sure?
PointedEars
Feb 1 '06 #4

P: n/a
Thomas 'PointedEars' Lahn <Po*********@web.de> writes:
Lasse Reichstein Nielsen wrote:

Even if it wasn't, "submitStep2" is not a variable in
any scope.


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


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

^^^^^
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Feb 1 '06 #5

P: n/a
Lasse Reichstein Nielsen wrote:
Thomas 'PointedEars' Lahn <Po*********@web.de> writes:
Lasse Reichstein Nielsen wrote:
Even if it wasn't, "submitStep2" is not a variable in
any scope. 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.


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.
How can the submitForm function's setTimeout call submitStep2?
Try:
var self = this;
setTimeout(function(){self.submitStep2();}, 20);

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


Correct. Sorry, I overlooked the first line, probably because it was late.
PointedEars
Feb 1 '06 #6

P: n/a
JRS: In article <23****************@PointedEars.de>, dated Wed, 1 Feb
2006 18:10:51 remote, seen in news:comp.lang.javascript, Thomas
'PointedEars' Lahn <Po*********@web.de> posted :

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.

--
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.
Feb 2 '06 #7

P: n/a
Thank you for the suggestion. I will try it in tomorrow and see what
happens.

Feb 3 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.