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


Groups > comp.lang.javascript > #32148

Re: Empty function

Path csiph.com!weretis.net!feeder4.news.weretis.net!feeder5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: Empty function
Date Mon, 09 Jan 2017 01:10:51 +0100
Organization PointedEars Software (PES)
Lines 74
Message-ID <3015126.QJadu78ljV@PointedEars.de> (permalink)
References <UPqdnRaDtOBAT-zFnZ2dnUU7-RHNnZ2d@westnet.com.au> <o4sppl$ub7$1@news.albasani.net> <l-ednZuM5IV2ne_FnZ2dnUU7-SXNnZ2d@westnet.com.au> <1552504.VLH7GnMWUR@PointedEars.de> <04OdnQ527cwRUu_FnZ2dnUU7-bXNnZ2d@westnet.com.au>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding 8Bit
X-Trace solani.org 1483920652 21388 eJwNxMERwDAIA7CVyAUTGAdzeP8RWj2EGyfmeSAcgvqGzOTvdsJQRvTulk92HyNNyaFYG//zASJWEkM= (9 Jan 2017 00:10:52 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Mon, 9 Jan 2017 00:10:52 +0000 (UTC)
User-Agent KNode/4.14.2
X-User-ID eJwFwYEBwDAEBMCV9MOLcRD2H6F3dvixXWlUW1skCdvE15OrwEPa8Zh6CH8unZRr8J6iTq1HSVxbpW5I/FiKFXI=
Cancel-Lock sha1:iOUaOU5Cku/MymK+BNOT13HCvhQ=
Face iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/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32148

Show key headers only | View raw


Andrew Poulos wrote:

> On 9/01/2017 9:40 AM, Thomas 'PointedEars' Lahn wrote:
>> Andrew Poulos wrote:
>>> […]
>>> var Drag = {
>>>    obj: null,
>>>    init: function(o, posX, posY, minX, minY) {
>>>      if (!o) return;
>>>      o.onmousedown = Drag.start;
>>>      o.root = o;
>>>      o.root.style.left = posX + "px";
>>>      o.root.style.top = posY + "px";
>>>      o.minX = minX;
>>>      o.minY = minY;
>>>      o.root.onDragStart = function() {};
>>>      o.root.onDragEnd = function() {};
>>>      o.root.onDrag = function() {};
>>
>> As indicated by “o.root.style”, “o.root” appears to store a reference to
>> a DOM element object.  In that case, the latter three lines are
>> error-prone:
>> […]
>>>    },
>>>    start: function(e) {
>>>      e = e || window.event;
>>>      var o = Drag.obj = this,
>>>          y = parseInt(o.root.style.top, 10),
>>>          x = parseInt(o.root.style.left, 10);
>>>      o.root.onDragStart(x, y);
>>
>> Given the augmented code, this line suggests that the author attempted to
>> augment a host object (see above), and that they have no clue how to
>> properly dispatch an event to such an object.
> 
> Thanks, I've stripped the references to onDragStart..., changed the
> event handler properties to all lowercase and it "works" in IE9+,
> Chrome...

You’re welcome.  But given that “o.root” refers to a host object to which 
the Law of Demeter does not fully apply (because it cannot safely be 
augmented with a method), there should be a method on the wrapper object 
with which to set the relevant “on…” properties of the wrapped object to 
retain the supposed functionality of the wrapper.

The problem here is that the current approach does not use a wrapping object 
in the first place but attempts to modify the target host object directly 
when init() is called.  The code needs to be refactored to avoid that, e. g.

  var my = Object.create(null);

  my.Dragable = function (target) {
    this.init(target);
  };

  Object.assign(my.Dragable.prototype, {
    /* to allow the wrapper to be reused for a different target */
    init: function (target) {
      if (this.target) this.clearEventListeners();

      this.target = target;
    },

    setEventListener: function (type, listener) {
      /* simplified */
      this.target["on" + type] = listener;
    }
  });

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | 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

Empty function Andrew Poulos <ap_prog@hotmail.com> - 2017-01-08 16:49 +1100
  Re: Empty function Martin Honnen <martin.honnen@gmx.de> - 2017-01-08 08:29 +0100
    Re: Empty function Andrew Poulos <ap_prog@hotmail.com> - 2017-01-08 20:05 +1100
      Re: Empty function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-01-08 23:40 +0100
        Re: Empty function Andrew Poulos <ap_prog@hotmail.com> - 2017-01-09 10:47 +1100
          Re: Empty function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-01-09 01:10 +0100
  Re: Empty function JJ <jj4public@vfemail.net> - 2017-01-08 20:53 +0700
  Re: Empty function "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-01-08 10:02 -0800
  Re: Empty function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-01-08 23:21 +0100

csiph-web