Path: csiph.com!news.freedyn.net!news.mb-net.net!open-news-network.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Overriding function and adding a bit Date: Thu, 11 May 2017 01:49:35 +0200 Organization: PointedEars Software (PES) Lines: 51 Message-ID: <20479369.6Emhk5qWAg@PointedEars.de> References: <5178377.MhkbZ0Pkbq@PointedEars.de> Reply-To: Thomas 'PointedEars' Lahn NNTP-Posting-Host: 170.224.197.178.dynamic.wless.zhbmb00p-cgnat.res.cust.swisscom.ch Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: gwaiyur.mb-net.net 1494460175 32749 178.197.224.170 (10 May 2017 23:49:35 GMT) X-Complaints-To: abuse@open-news-network.org NNTP-Posting-Date: Wed, 10 May 2017 23:49:35 +0000 (UTC) User-Agent: KNode/4.14.2 X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. Thomas 'PointedEars' Lahn wrote: >> Doc O'Leary wrote: >> ^^^^^^^^^^^ >> Get a real name. > > Attempt at humor, or trolling from the get-go? Are the subscribers of this newsgroup supposed to believe that “Doc O’Leary” is your real name? >> > Andrew Poulos wrote: >> >> var myObjLayerMoveTo = window.ObjLayerMoveTo; >> >> >> >> window.ObjLayerMoveTo = function(x, y) { >> >> if (this.id == "foo") return; >> >> myObjLayerMoveTo(x, y); >> >> }; >> >> >> >> Is this the way to approach this? >> > Goodness, no. A major point of OOD is that you can override the >> > method in the hierarchy at the appropriate object level. >> Pray tell, what would be the object here? > > Whatever the context “this” is referring to such that the id can be > compared in the first place. “this” is not necessarily referring to the same object that the function is called as a method of. The original code of the function is: function ObjLayerMoveTo(x, y) { /* 100+ lines of spaghetti code */ } >> > Define an empty ObjLayerMoveTo function on your “foo” object. >> Who said anything about a “‘foo’ object”? He wants to *override the >> function*. > > If you don’t see the use of “foo” in the example code, I cannot help > you. "foo" is a primitive string value there. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail.