How to call event as a function in mozilla

Discussion in 'Javascript' started by Jadow, Jul 7, 2003.

  1. Jadow

    Jadow Guest

    I have a function that is used as an event for some parts of the
    script.
    i.e.
    function somethind(e) {
    if (!e.currentTarget.documentElement ){
    ...
    }
    }

    I need to call this function manually (not by assigning it to an
    event) Yet I cannot seem to deal with 'e'.
    If I call it as: something(e); I get a 'not defined', if I ommit it I
    get an undefined.
    For some reason 'e' is undefined in the calling script. What decides
    when it is available as an event object? and how can I resolve this
    issue?

    Thanks
    Joshua
     
    Jadow, Jul 7, 2003
    #1
    1. Advertising

  2. (Jadow) writes:

    > I have a function that is used as an event for some parts of the
    > script.


    It is an event handler. The "e" will be the event then.

    > function somethind(e) {
    > if (!e.currentTarget.documentElement ){
    > ...
    > }
    > }


    That requires the currentTarget property to be a document object.

    > I need to call this function manually (not by assigning it to an
    > event) Yet I cannot seem to deal with 'e'.
    > If I call it as: something(e); I get a 'not defined', if I ommit it I
    > get an undefined.


    If you write
    something(e);
    and "e" is not a defined variable, then it is ofcourse an error. You have
    to add an event as argument (or any object with a currentTarget property).
    Try
    something({currentTarget:document});

    > For some reason 'e' is undefined in the calling script.


    That reason is proabably that it hasn't been defined.

    > What decides when it is available as an event object?


    When you assign it. The "e" in the function definition only
    exists inside the function. It is a local name for the argument
    to the function.

    /L
    --
    Lasse Reichstein Nielsen -
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Jul 7, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Henri
    Replies:
    9
    Views:
    1,862
    Toby Inkster
    Feb 22, 2005
  2. grbgooglefan
    Replies:
    2
    Views:
    438
    Pascal Bourguignon
    Jan 30, 2008
  3. grbgooglefan
    Replies:
    4
    Views:
    457
    Kenny McCormack
    Jan 30, 2008
  4. grbgooglefan
    Replies:
    0
    Views:
    409
    grbgooglefan
    Jan 30, 2008
  5. Replies:
    3
    Views:
    414
    ExGuardianReader
    Jan 8, 2005
Loading...

Share This Page