Path: csiph.com!.POSTED.204-73-239-109.cust.centrio.cz!not-for-mail From: Cezary Tomczyk Newsgroups: comp.lang.javascript Subject: Re: Object.defineProperties Date: Fri, 5 May 2017 19:37:48 +0200 Organization: csiph.com Internet News Service Message-ID: References: <1943190.NgBsaNRSFp@PointedEars.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 5 May 2017 17:37:49 +0000 (UTC) Injection-Info: csiph.com; posting-host="204-73-239-109.cust.centrio.cz:109.239.73.204"; logging-data="43521"; mail-complaints-to="admin@kev009.com" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 In-Reply-To: <1943190.NgBsaNRSFp@PointedEars.de> Xref: csiph.com comp.lang.javascript:33223 On 05/05/2017 18:14, Thomas 'PointedEars' Lahn wrote: > Cezary Tomczyk wrote: [...] >> I use: >> >> function isTypeOf(obj, typeToCheck) { >> if (arguments.length < 2) { >> return false; >> } >> return Object.prototype.toString.call(obj).slice(8, > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >> -1).toLowerCase() === typeToCheck.toLowerCase(); > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >> } >> >> which gives me more precisely a type of object. > > I hope you have optimized that somewhat. I can't find a reliable way at the moment. Perhaps I should combine few methods, but that might be an overengineering. >> The Object.defineProperties says about object, but function, array are >> also objects. That's why: >> >> if (typeof obj !== 'object' || obj === null) >> throw new TypeError('bad obj'); >> >> looks like a bug to me. > > typeof [] === "object", so that is OK. (common misconception) In a sense of that [] is an object - yes, but I'd prefer to know that tested object is in fact an Array type. Operator instanceof looks promising, but I need to check it anyway. > typeof function () {} === "function", so that is not OK in theory; however, > one might decide that it is not OK to modify function objects. Functions are objects so they can be extended like any other objects. -- Cezary Tomczyk http://www.ctomczyk.pl/ https://www.aslint.org/ - Accessibility validation tool