Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #31697

Re: Why does savepng workl with eventlistener but not by call from form?

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: Why does savepng workl with eventlistener but not by call from form?
Date 2016-11-11 16:08 +0100
Organization PointedEars Software (PES)
Message-ID <2828265.aV6nBDHxoP@PointedEars.de> (permalink)
References <58b433c6-37a6-45de-bc70-05ec835510ff@googlegroups.com> <bfa1965d-1bf2-4024-86e3-ce7535870d2b@googlegroups.com> <17n7y8md13g1b$.kznrbim03ls$.dlg@40tude.net>

Show all headers | View raw


JJ wrote:

> On Thu, 10 Nov 2016 15:47:37 -0800 (PST), jonas.thornvall@gmail.com wrote:
>> But what does click() do, it can't start the eventhandler because it is
>> inside the function that will be called from the handler, restart?
> 
> click() simulates a click event.
> It's OOP, so click() belongs to anobject.
> So, anobject.click() clicks the anobject.

It is a proprietary, legacy method, though, not even defined in WHATWG HTML.  
The standards-compliant approach is to dispatch a synthetic “click” event to 
the element object.

This has become a lot easier since the UI Events Specification that 
deprecated the Event::init*Event() methods, with their insanely long 
parameter lists, in favor of proper constructors:

  anObject.dispatchEvent(new MouseEvent("click", {
    view: document.defaultView,
    bubbles: true,
    cancelable: true
  }));

[Formerly:

  var mouseEvent = document.createEvent("MouseEvents");
  mouseEvent.initMouseEvent("click", true, true, window,
    0, 0, 0, 0, 0, false, false, false, false, 0, null);
  anObject.dispatchEvent(mouseEvent);

Lesson to be learned: Design functions/methods to accept references to 
parameter/option objects, and not more than 5 arguments [unless it is a list 
of values of equal meaning, see e.g. Math.max()].  Otherwise nobody is going 
to remember the correct argument order, you will be sacrificing flexibility, 
and the caller’s code will look like Chinese (when they are not Chinese).]

<https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events> pp.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Why does savepng workl with eventlistener but not by call from form? jonas.thornvall@gmail.com - 2016-11-10 14:35 -0800
  Re: Why does savepng workl with eventlistener but not by call from form? jonas.thornvall@gmail.com - 2016-11-10 15:47 -0800
    Re: Why does savepng workl with eventlistener but not by call from form? JJ <jj4public@vfemail.net> - 2016-11-11 21:05 +0700
      Re: Why does savepng workl with eventlistener but not by call from form? jonas.thornvall@gmail.com - 2016-11-11 06:35 -0800
        Re: Why does savepng workl with eventlistener but not by call from form? JJ <jj4public@vfemail.net> - 2016-11-11 22:01 +0700
          Re: Why does savepng workl with eventlistener but not by call from form? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-11-11 16:21 +0100
      Re: Why does savepng workl with eventlistener but not by call from form? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-11-11 16:08 +0100
        Re: Why does savepng workl with eventlistener but not by call from form? Scott Sauyet <scott@sauyet.com> - 2016-11-26 21:09 +0000
          Re: Why does savepng workl with eventlistener but not by call from form? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-11-26 22:47 +0100
            Re: Why does savepng workl with eventlistener but not by call from form? "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-11-27 00:11 +0100
              Re: Why does savepng workl with eventlistener but not by call from form? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-11-27 00:57 +0100
                Re: Why does savepng workl with eventlistener but not by call from form? Scott Sauyet <scott@sauyet.com> - 2016-11-27 01:08 +0000
                Re: Limit number of function parameters (was:Why does savepng workl with eventlistener but not by call from form?) "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-11-28 18:17 +0100
                Re: Limit number of function parameters (was:Why does savepng workl with eventlistener but not by call from form?) Scott Sauyet <scott@sauyet.com> - 2016-11-29 02:15 +0000
                Re: Limit number of function parameters "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-12-02 20:24 +0100
                Re: Limit number of function parameters Scott Sauyet <scott@sauyet.com> - 2016-12-03 01:58 +0000

csiph-web