access from inner object

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

    access from inner object

    i get "name_ is undefined" error. how should i access ClassA object
    from inside this inner function/object?

    in Java i would write something like this alert(ClassA.th is.name_)

    <html>
    <head>
    <script language="JavaS cript">
    function ClassA(id) {
    this.name_ = "class A";
    this.el = document.getEle mentById(id);

    this.el.onmouse over = function() {
    this.style.colo r = "red";
    alert(name_);
    }
    }
    </script>
    </head>
    <body onload="new ClassA('span')" >
    <span id="span">i'm the <SPAN></span>
    </body>
    </html>
  • marius

    #2
    Re: access from inner object

    "Janwillem Borleffs" <jwb@jwbfoto.de mon.nl> wrote in message news:<3f15b99a$ 0$28890$1b62eed f@news.euronet. nl>...
    [color=blue]
    > That's because you are assigning the onmouseover event to the element, but
    > assigning the name to the object.
    >
    > You should change the order to make this work:
    >
    > function ClassA(id) {
    > this.el = document.getEle mentById(id);
    > this.el.name_ = "class A";
    > this.el.onmouse over = function() {
    > this.style.colo r = "red";
    > alert(this.name _);
    > }
    > }[/color]

    i specifically wanted name_ to be a property of ClassA object.
    however, i found already a solution:

    function ClassA(id) {
    this.el = document.getEle mentById(id);
    this.name_ = "class A";

    this.el.super_ = this; // give el object a reference to ClassA object
    this.el.onmouse over = function() {
    this.style.colo r = "red";
    alert(this.supe r_.name_);
    }
    }

    Comment

    Working...