Frage

Aus XBL Methode, wenn ich eine andere Methode aufrufen müssen, ich mag:

        <method name="myMethod_1">
            <body>
                <![CDATA[
                    // do staff
                ]]>
            </body>
        </method>


        <method name="myMethod_2">
            <body>
                <![CDATA[
                    document.getElementById("thisElementID").myMethod_1();
                ]]>
            </body>
        </method>

Ich würde gerne wissen, ob es eine Möglichkeit die lokale Methode, ohne dass das Element id anrufen? Ich habe versucht, this.myMethod_1() aber es sagt, die Methode gibt es nicht.

War es hilfreich?

Lösung

can you show us code calling myMethod_2? If you call it like: document.getElement(...).myMethod_2() that's fine, but if you have something like someElement.addEventHandler("click", myxbl.myMethod_2,...); that won't work since event target will be this.

This is important for determining what is this in that context

EDIT: (Tom's reply)

ow, think I got it.. it's exactly this the problem.. I'm calling it from a keypress listener of another document, and the "this" was not what I think..

Andere Tipps

In the specific case of an event listener, there is another way around the problem, and that is to pass the element itself as the listener. Of course you only get one handleEvent method, so this is less useful if you're listening to lots of different events on lots of different event targets.

<implementation implements="nsIDOMEventListener">
  <method name="handleEvent">
    <parameter name="aEvent"/>
    <body>
      <![CDATA[
        // do stuff
      ]]>
    </body>
  </method>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top