473,394 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

problems with objects, argument.caller and setTimeout

Hi,

the structure of my source code is like this:
<script>
C = function(){
//some initialization
}

C.prototype.start = function{
//some action
setTimeout(arguments.caller.callee, "200");
}

var obj = new C();
obj.start();
</script>

This should execute the method start every 200 milisec, but (in some
cases)
it gives me an error because arguments.caller is null. Is there a
"direct" method to use setTimeout without this arguments.??? stuff?

BTW: I'm working with IE Version >= 5.0

Is there a better solution to get start work ?

I am very grateful for every hint
Oliver
Jul 23 '05 #1
5 2539
bi*********************@yahoo.com (oliver) writes:
<script> Use:
<script type="text/javascript">
The type attribute is required in HTML 4.
C.prototype.start = function{
//some action
setTimeout(arguments.caller.callee, "200");
The "arguments" object doesn't have a "caller" property. It does
have "callee", but only in modern browsers.

What are you trying to do? (You have to say, because when your code
is wrong, we can't necessarily guess it from that)

(And "200" should not be a string, but a number, so lose the quotes).
This should execute the method start every 200 milisec, but (in some
cases) it gives me an error because arguments.caller is null.
Only in some cases? Which cases? What do you change between the cases
that work and the ones that doesn't?
Is there a "direct" method to use setTimeout without this
arguments.??? stuff?
Your problem is to refer to the function itself inside it. It's not
important that you use it with setTimeout.
BTW: I'm working with IE Version >= 5.0
Which version? All of them?
Is there a better solution to get start work ?


Try:
---
C.prototype.start = function start() {
//some action
setTimeout(start, 200);
};
---

However, it's probably not what you want, because the calls to start
from setTimeout/setInterval will not be as methods of the C object,
i.e., the "this" value will not be set to that object while executing
start. To achieve that, you'll have to wrap the call in a closure that
knows the object:

---
C.prototype.start = function start() {
//some action
if (!this.timerId) {
var _this = this;
var recall = function() { _this.start(); };
this.timerId = setInterval(recall, 200);
}
---
or
---
C.prototype.start = function start() {
//some action
if (!this.recall) {
var _this = this;
this.recall = function() { _this.start(); };
}
setTimeout(this.recall, 200);
}
---

Good luck
/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.'
Jul 23 '05 #2
Lasse Reichstein Nielsen wrote:
bi*********************@yahoo.com (oliver) writes:
C.prototype.start = function{
//some action
setTimeout(arguments.caller.callee, "200");


The "arguments" object doesn't have a "caller" property. It does
have "callee", but only in modern browsers.


Function objects have a `caller' property in javascript:

function foo()
{
alert(foo.caller); // alerts the source code of bar()
}

function bar() {
foo();
alert(bar.caller); // alerts the whole source code or `null'
}

bar();
PointedEars
Jul 23 '05 #3
Thomas 'PointedEars' Lahn <Po*********@nurfuerspam.de> writes:
Function objects have a `caller' property in javascript:


In JavaScript (the Netscape implementation of ECMAScript), functions
have an "arguments" property (deprecated in version 1.4) with a
"caller" property (deprecated in 1.3).

It seems "funvalue.caller" was introduced in JavaScript 1.5 (in
Mozilla, not in Netscape 4). The documentation is misleading, as it
says "caller" is a property of "Function", while it is actually a
property of "Function.prototype".

For IE, JScript also has a "funvalue.caller" property since version 2.
<URL:http://msdn.microsoft.com/library/en-us/script56/html/js56jsprocaller.asp>

It's still not part of ECMAScript, so other browsers probably doesn't
understand it (Opera doesn't). If I don't say anything else, when I talk
about language features, I'm talking about ECMAScript v3.

/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.'
Jul 23 '05 #4
Lasse Reichstein Nielsen wrote:
Thomas 'PointedEars' Lahn <Po*********@nurfuerspam.de> writes:
Function objects have a `caller' property in javascript:
In JavaScript (the Netscape implementation of ECMAScript), functions
have an "arguments" property (deprecated in version 1.4) with a
"caller" property (deprecated in 1.3).


In my JavaScript 1.5 reference implementation (mozilla.org SpiderMonkey)
the `arguments' property does not have a `caller' property, but Function
objects have.
It seems "funvalue.caller" was introduced in JavaScript 1.5 (in
Mozilla, not in Netscape 4).
What's the problem?
The documentation is misleading, as it says "caller" is a property of
"Function", while it is actually a property of "Function.prototype".
The Netscape JavaScript References are flawed not only in this regard.
[...]
It's still not part of ECMAScript, so other browsers probably doesn't
understand it (Opera doesn't). If I don't say anything else, when I
talk about language features, I'm talking about ECMAScript v3.


I'll remember you the next time when you use e.g. the `window' object in
this context.
PointedEars
Jul 23 '05 #5
Thomas 'PointedEars' Lahn <Po*********@nurfuerspam.de> writes:
It's still not part of ECMAScript, so other browsers probably doesn't
understand it (Opera doesn't). If I don't say anything else, when I
talk about language features, I'm talking about ECMAScript v3.


I'll remember you the next time when you use e.g. the `window' object in
this context.


Hmm, I guess I'll have to rethink that statement :)

Ok, at least ECMAScript was what I was thinking about when I said that there
was no "caller" property.

/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.'
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Justin Koivisto | last post by:
I am having a problem with Internet Explorer and javascript on a WYSIWYG editor I am creating. It all works in Mozilla, but IE returns flase for queryCommandEnabled('forecol'). JS isn't my strong...
5
by: Aaron | last post by:
I'm having problems getting my popup menu to work correctly, and was hoping someone here could point me in the right direction. I have the following script: <script> var activeMenu=""; ...
6
by: Jamal | last post by:
I am working on binary files of struct ACTIONS I have a recursive qsort/mergesort hybrid that 1) i'm not a 100% sure works correctly 2) would like to convert to iteration Any comments or...
2
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the...
12
by: shafiqrao | last post by:
Hello everyone, I have a script that runs in IE great, but in firefox it has problems. I understand that there are some objects that are accessed differently in IE and Mozilla. Can anybody let...
3
by: matko | last post by:
This is a long one, so I'll summarize: 1. What are your opinions on raising an exception within the constructor of a (custom) exception? 2. How do -you- validate arguments in your own...
5
by: wshaer | last post by:
Hi This is the task: and these are my classes: public class Engine{ // Declare the varibles
11
by: MikeT | last post by:
This may sound very elementary, but can you trap when your object is set to null within the object? I have created a class that registers an event from an object passed in the constructor. When...
409
by: jacob navia | last post by:
I am trying to compile as much code in 64 bit mode as possible to test the 64 bit version of lcc-win. The problem appears now that size_t is now 64 bits. Fine. It has to be since there are...
0
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
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...
1
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...
0
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.