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 08:32:55 +0200 Organization: csiph.com Internet News Service Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Fri, 5 May 2017 06:32:56 +0000 (UTC) Injection-Info: csiph.com; posting-host="204-73-239-109.cust.centrio.cz:109.239.73.204"; logging-data="15248"; 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: Xref: csiph.com comp.lang.javascript:33206 On 05/05/2017 04:39, Stefan Ram wrote: > ram@zedat.fu-berlin.de (Stefan Ram) writes: >> Cezary Tomczyk writes: >>> Native built-in Object.defineProperties method allows me to add >>> properties to a function as the function is an object. >> The Web gives: >> function isObject(val) { >> if (val === null) { return false;} >> return ( (typeof val === 'function') || (typeof val === 'object') ); >> } >> . The above might not work with host objects, which might >> have even other types. > > However, according to Flanagan, a host object may not > return »undefined«, »boolean«, »number«, or »string« as > its type. So, another way to check whether something is > an object might be to check that its type is not one > of those. Yes, but typeof for [] will still returns "object". One more thing. Regarding: let a = new String( "abc" ); console.log( Object.prototype.toString.call( a ) ); Object.defineProperty ( a, Symbol.toStringTag, { get: function() { return "Number"; }}); console.log( Object.prototype.toString.call( a ) ); if typing "a instanceof String" then there is "true". So, perhaps instanceof is the way of checking the type of object instead of Object.prototype.toString.call or typeof or Object.defineProperty[...] -- Cezary Tomczyk http://www.ctomczyk.pl/ https://www.aslint.org/ - Accessibility validation tool