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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wolfram Heinz

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

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

    Example:
    -->
    catch(myerrorob ject)
    alert(myerrorob ject.filename);
    {
    my_function('bl a: ',myerrorobject );
    }
    <---

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

    Regards,
    Wolfram Heinz

  • Michael Winter

    #2
    Re: How can I avoid type-conversion (object variable to string)

    Wolfram Heinz wrote:

    [snip]
    [color=blue]
    > -->
    > catch(myerrorob ject)
    > alert(myerrorob ject.filename);
    > {
    > my_function('bl a: ',myerrorobject );
    > }
    > <---
    >
    > I get the "myerrorobject. filename" in the alert-Box, but I get an
    > "undefined"-error, if I try to access myerrorobject.f ilename (or other
    > properties) in the function "my_functio n".
    > Why?[/color]

    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(myerrorob ject) {
    alert(myerrorob ject.filename);
    }
    {
    my_function('bl a: ', 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.

    Comment

    Working...