'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

'in' operator and feature detection technique...

From: Luke Matuszewski <matuszewski.lukasz@gmail.com>
Date: Thu Feb 09 2006 - 17:09:08 CET

We all know that feature detection technique works from very beggining
of user-agents supporting JavaScript. We can alway check if eg.
document has a write property or smth else:

if(document.write) {

}

We could do that for all of objects, so i have been surprised when i
found 'in' operator, which for above example would be used like this:

if("write" in document) {

}

So i have questioned myself what for ? I can always do:

if(document["write"]) {

}

or even
var prop = [...];

if(document[prop]) {

}

which is supported better then 'in' operator ('in' is supported since
W. IE 5.5 and NN 6 - around 2000 year). I can only guess that 'in' was
provided in W. IE 5.5 only for convenience... but that is my guess and
someone more knowlegable could write here some more opinions on this
operator...

B.R.
Luke Matuszewski
Received on Mon May 1 03:12:15 2006