Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: What's wrong with this code? Date: Thu, 26 Feb 2015 15:37:40 +0000 Organization: A noiseless patient Spider Lines: 28 Message-ID: <87mw40n0or.fsf@bsb.me.uk> References: <8761aopx65.fsf@bsb.me.uk> <2083952.afr504CXY5@PointedEars.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="27375"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+gaVV6eUzzTYEukwB3obHC5r9apSPv66o=" Cancel-Lock: sha1:IAqRtFOtPU4bp2I4QmHcYG6ubMM= sha1:f2RNVMCmyQjQfDlJZetTuK7Fx+Q= X-BSB-Auth: 1.2c6be32d2b436039cd92.20150226153740GMT.87mw40n0or.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:26939 Thomas 'PointedEars' Lahn writes: > Ben Bacarisse wrote: > >> denissavenok@gmail.com writes: >>> The function doesn't work as expected. Why? >>> >>> var isUndefinedOrNull = function(obj) { >>> return /^(?:undefined|null)$/.test(typeof obj); >>> }; >> >> If the type of obj is Null, typeof is defined to yield 'object'. >> >> You might (in some very odd implementation) get 'null' from typeof, but >> that's only because the result is up to the implementation in some very >> specific cases. > > To be exact, a conforming implementation of ECMAScript could only provide > "null" as the result of a “typeof” operation if the operand was a reference > to a host object. To be more exact, only if the reference is to a host object that does not implement [[Call]]. For references to callable object, both native and host, the result must be 'function'. -- Ben.