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

How can I avoid type-conversion (object variable to string)

P: n/a
Hi there,
How can I avoid type-conversion (object variable --> string) when
passing an object variable to a function?

Example:
-->
catch(myerrorobject)
alert(myerrorobject.filename);
{
my_function('bla: ',myerrorobject);
}
<---

I get the "myerrorobject.filename" in the alert-Box, but I get an
"undefined"-error, if I try to access myerrorobject.filename (or other
properties) in the function "my_function".
Why?

Regards,
Wolfram Heinz

Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Wolfram Heinz wrote:

[snip]
-->
catch(myerrorobject)
alert(myerrorobject.filename);
{
my_function('bla: ',myerrorobject);
}
<---

I get the "myerrorobject.filename" in the alert-Box, but I get an
"undefined"-error, if I try to access myerrorobject.filename (or other
properties) in the function "my_function".
Why?


If that's your literal code, it's because myerrorobject doesn't exist
when the function call occurs. The code will be parsed as:

catch(myerrorobject) {
alert(myerrorobject.filename);
}
{
my_function('bla: ', myerrorobject);
}

Notice that there are two blocks. The catch identifier will only exist
in the first.

To be honest, I'm surprised that would work at all. A catch clause
must be followed by a block unlike if, for example, which may be
followed by either a statement or a block.

If what you posted is a typo, I think you'll have to post a more
complete example.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.