Re: 'in' operator and feature detection technique...
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: 'in' operator and feature detection technique...

From: Thomas 'PointedEars' Lahn <PointedEars@web.de>
Date: Fri Feb 10 2006 - 00:13:47 CET

VK wrote:

> ('property' in someObject) is not intended for features test - though
> it can be used and it is used this way (when the support for
> prehistoric browsers is not a requirement).

So your history begins not long before 2000 CE? That would explain some
of your misconceptions, although not all of them.
 
> But originally it was introduced with it counterpair hasOwnProperty for
> prototype-based inheritance management.

Nonsense.

JavaScript 1.0 and ECMAScript implementations (e.g. JavaScript 1.1+, JScript
1.0+) have always been languages that used prototype-based inheritance.

The `in' operator was introduced in JavaScript 1.5 (Mozilla/5.0 rv:0.6,
November 2000), JScript 5.5 (IE 5.5, July 1999) [1], and ECMAScript
Edition 3 (December 1999).

The `hasOwnProperty' method was introduced in JavaScript 1.5, JScript 5.5,
and ECMAScript Edition 3.

Since the current major version of IE is 6.0, that would mean you consider
its previous major version, IE 5.0, historic already, even though it is
still used. I take that as another proof that what you post should be
handled with extreme care.

> P.S.
> The "in" operator checks if an object has a property named property. It
> also checks the object's prototype to see if the property is part of
> the prototype chain.

The operator simply uses the prototype chain, by calling the internal
GetValue() method (ES3 Final, 8.7.1) which calls the internal [[Get]]
method (8.6.2.1) which calls the [[Get]] method of [[Prototype]] if it
is not `null' (steps 4 and 5), _up to its end_ (including the prototype
of the prototype aso.). It does not check only the object's prototype
explicitly as that would not be sufficient.

PointedEars
___________
[1] The JScript and JScript.NET References say it was introduced in JScript
    1.0 already, that would mean IE 3.0 (August 1996). However, I find that
    hard to believe and think that is an error, since a) ECMAScript Ed. 3
    was not published yet and b) it also says that `for (... in ...)' was
    not supported before JScript 5.5 (IE 5.5). I would appreciate it if
    someone could provide reliable test results to back up either claim.
Received on Mon May 1 03:13:31 2006