Path: csiph.com!news.swapon.de!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: Object.defineProperties Date: Sat, 06 May 2017 22:21:59 +0200 Organization: PointedEars Software (PES) Lines: 80 Message-ID: <1982276.iZASKD2KPV@PointedEars.de> References: <1943190.NgBsaNRSFp@PointedEars.de> <1592229.TLkxdtWsSY@PointedEars.de> <2032926.ElGaqSPkdT@PointedEars.de> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1494102119 31170 eJwNx8ERACAIA7CVqEDRcVBk/xH08oorwRNGp3l/GXo1TeYAfi5K2FwLI7orT1MmYmM3h7AeDtgQyg== (6 May 2017 20:21:59 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Sat, 6 May 2017 20:21:59 +0000 (UTC) User-Agent: KNode/4.14.2 Cancel-Lock: sha1:wHk0akskWd89BWcrsDr1luPhMc4= X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. On 06/05/2017 16:43, Thomas 'PointedEars' Lahn wrote: >> Cezary Tomczyk wrote: >>> On 05/05/2017 20:11, Thomas 'PointedEars' Lahn wrote: >>>> To begin with, you should have >>>> >>>> var _toString = {}.toString; >>>> >>>> function isTypeOf(obj, typeToCheck) { >>>> if (arguments.length < 2) { >>>> return false; >>>> } >>>> return _toString.call(obj).slice(8, -1).toLowerCase() === >>>> typeToCheck.toLowerCase(); >>>> } >>> >>> Tiny optimisation, but that's fine. :-) >> >> Tiny optimization with big impact, I think. It saves >> >> - 1 lookup along the scope chain up to the global object for “Object” >> *every time the function is called* >> >> - 2 lookups along the prototype chain each for “prototype” and >> “toString” >> *every time the function is called* >> >> and removes the dependency on a potentially non-initial value of >> “Object.prototype” and “Object.prototype.toString”. > > That's true, but it is also important to mention that the impact is > significant in case of hundred operations at the same time. It is more significant if this function is called several times in a single- threaded environment: the slower it is, the slower does the program run. >>> Finally I rewrote it a bit: >>> […] >>> function isTypeOf(obj, typeToCheck) { >>> […] >>> if (arguments.length !== 2) { >> This change does not make sense to me. “< 2” was clearer. > > Passing 1 argument doesn't make sense and that's why I've used !== 2. Yes, but … >>> return false; >>> } >>> >>> objectType = typeof obj; >> IMO, DRY demands declaration and initialization in one statement, if >> possible. > > I did it on purpose. If argument will be !== 2 then it is not efficient > to initialize anything before. [Your reply here does not have anything to do with what you are replying to.] … why should the function return “false” if I pass 3 or more arguments to it? Besides, an insufficient number of arguments should throw an exception instead. >> The question remains: What is being *gained* by this comparably >> inefficient precision instead of duck typing? _Not_ all things >> that *can* be done also *should* be done. > > The gain is to get the real type (let me call it like that) of object. Why is that important? -- PointedEars FAQ: | | Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.