Hi
This might be a bit tricky.
I want to call a method of a class using the setTimeout code, ok, can do this
like this:
var instance = this;
timerID = window.setTimeout( function() { instance.Method(); }, 1000);
Now I want to call a method a number of times from with the class and when they
have all finished I want a second method to be called, I don't want the methods
themselves to be altered, i.e. I want this to be generic.
Here was my idea:
var timerCounter = 0
function CallFunc(func, callbackFunc)
{
timerCounter--;
if(timerCounter == 0)
{
callbackFunc()
}
}
function DoAsyncRequest(func, callbackFunction)
{
timerCounter++;
return window.setTimeout( CallFunc(func, callbackFunction), 1);
}
You would call this using something like:
timerId = DoAsyncRequest(this.method(), this.method2());
How could I do this, tryed using eval to no avail. I just don't know the
language well enough yet.
Any ideas? Example code would be worth a million words please :-)
Ta
F 3 2067
On 12 Feb 2004 07:22:12 -0800, <fo******@yahoo.co.uk> wrote:
[snip] You would call this using something like:
timerId = DoAsyncRequest(this.method(), this.method2());
How could I do this, tryed using eval to no avail. I just don't know the language well enough yet. Any ideas? Example code would be worth a million words please :-)
Try dropping the parentheses so you have:
timerId = DoAsyncRequest( this.method, this.method2 );
With your original example, you're calling method() and method2(), not
passing a reference to them. The body of DoAsyncRequest will never receive
anything about the two methods, only their return values, if any.
If this doesn't help, you'll need to provide more context: a example that
shows how it would be used in a webpage.
Mike
--
Michael Winter M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
This works, classmethod is called the correct number of times by classmethod2
is only called once, after they have all been called.
Thanks for you help
<script>
function SomeClass()
{
this.ClassMethod = SomeClassMethod
this.ClassMethod2 = SomeClassMethod2
}
function SomeClassMethod()
{
alert("method")
}
function SomeClassMethod2()
{
alert("method2")
}
//--------------------------------
var timerCounter = 0
function CallFunc(func, callbackFunc)
{
func()
timerCounter--;
if(timerCounter == 0)
{
callbackFunc()
}
}
function DoAsyncRequest(func, callbackFunction)
{
timerCounter++;
return window.setTimeout( function(){CallFunc(func, callbackFunction)}, 500);
}
//timerId = DoAsyncRequest(this.method, this.method2);
var someClass = new SomeClass;
timerId = DoAsyncRequest(someClass.ClassMethod, someClass.ClassMethod2);
timerId = DoAsyncRequest(someClass.ClassMethod, someClass.ClassMethod2);
timerId = DoAsyncRequest(someClass.ClassMethod, someClass.ClassMethod2);
timerId = DoAsyncRequest(someClass.ClassMethod, someClass.ClassMethod2);
timerId = DoAsyncRequest(someClass.ClassMethod, someClass.ClassMethod2);
timerId = DoAsyncRequest(someClass.ClassMethod, someClass.ClassMethod2);
</script>
[This followup was posted to comp.lang.javascript and a copy was sent to
the cited author.]
In article <ac**************************@posting.google.com >, fo******@yahoo.co.uk says... This works, classmethod is called the correct number of times by classmethod2 is only called once, after they have all been called. Thanks for you help
[snip]
You should review the thread I started on the 14th called "Exception
when calling a DOM method using a reference to it". There are
implications for object-oriented code, specifically when using the
'this' operator, and passing method references. I didn't know about this
at the time of my reply to you.
Mike This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mike C. Fletcher |
last post by:
I'm looking at rewriting parts of Twisted and TwistedSNMP to eliminate
__del__ methods (and the memory leaks they create). Looking at the docs
for 2.3's weakref.ref, there's no mention of whether...
|
by: Jure Sah |
last post by:
Hello,
I have been promising an object orientated ASM IDE for a while now.
Trying to make the best of what is already here, I have made a compiler,
that will parse XML code and output ASM files....
|
by: Daniel |
last post by:
Hello =)
I have an object which contains a method that should execute every x ms. I
can use setInterval inside the object construct like this -
self.setInterval('ObjectName.methodName()',...
|
by: Christopher Jastram |
last post by:
I'm a self-taught programmer, so this might be a pretty dumb question.
If it is, please point me in the right direction and I shall
apologize profusely.
I have a question regarding C++ and...
|
by: Chris |
last post by:
Hi.
I have a ibrary I'm trying to use via javascript within IE. This
library uses an asynchronous model where I call into a function and
pass it a callback function as one of its arguments. My...
|
by: Joe Martin |
last post by:
Has anyone made use of PKWare's PKCDL.DLL for the Implode and Explode
functions?
I have been able to successfully define everything correctly and even
get the invoked function (Explode) to run...
|
by: GT |
last post by:
Could someone please explain the difference of (refer to example code below)
d.BeginInvoke("some text", null,null); //Alternative A
and
BeginInvoke( d, new object { "some text" } ...
|
by: Glenn |
last post by:
I have a class which has an async function which uses begininvoke on a
delegate to run a private function in the class. The class has an
event which reports back i) a unique identifier for that...
|
by: alck1234 |
last post by:
Hi,
I need help on my mini project on object orientated programming. The
question goes like this:
A mini-mart has just installed a bar code reader to improve efficiency
at their checkouts....
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |