Path: csiph.com!weretis.net!feeder4.news.weretis.net!feeder5.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn 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> References: <1552504.VLH7GnMWUR@PointedEars.de> <04OdnQ527cwRUu_FnZ2dnUU7-bXNnZ2d@westnet.com.au> Reply-To: Thomas 'PointedEars' Lahn 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/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg== X-NNTP-Posting-Host: eJwFwQkRwEAIBDBLfAtUDssN/iU0gafmViQycLh7EEUVmdL+0L1qHwn4xAhFg22j58qwxQ8OqRCF X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. 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: | | Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.