Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #26938
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: What's wrong with this code? |
| Date | 2015-02-26 16:04 +0100 |
| Organization | PointedEars Software (PES) |
| Message-ID | <2083952.afr504CXY5@PointedEars.de> (permalink) |
| References | <b2751271-cbda-4bcd-9217-a37eb3fa58b0@googlegroups.com> <8761aopx65.fsf@bsb.me.uk> |
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. An implementation that provided "null" for a primitive
value or a reference to a native object would be non-conforming, which in
*this* case means it is borken.
<http://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,
%201st%20edition,%20June%201997.pdf#page=50>
<http://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,
%202nd%20edition,%20August%201998.pdf#page=55>
<http://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,
%203rd%20edition,%20December%201999.pdf#page=59>
<http://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262%205th%20edition%20December%202009.pdf#page=81>
--
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
What's wrong with this code? denissavenok@gmail.com - 2015-02-26 01:18 -0800
Re: What's wrong with this code? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-02-26 12:17 +0100
Re: What's wrong with this code? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-02-26 14:25 +0000
Re: What's wrong with this code? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-02-26 16:04 +0100
Re: What's wrong with this code? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-02-26 15:37 +0000
Re: What's wrong with this code? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-02-26 17:09 +0100
Re: What's wrong with this code? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-02-26 14:09 -0300
csiph-web