Skip to content

Instantly share code, notes, and snippets.

@Cycymomo
Last active January 3, 2016 14:29
Show Gist options
  • Save Cycymomo/8476349 to your computer and use it in GitHub Desktop.
Save Cycymomo/8476349 to your computer and use it in GitHub Desktop.
document.all.falsy.md

L'exception qui confirme la règle

En JavaScript, comme spécifié par ECMAScript 5, tous les objets (non primitifs) sont évalués à true (on dit en anglais qu'ils sont truthy). Certains sont évalués à false (ils sont dits falsy) :

  • falsy : undefined, null, false, +0, -0, NaN, ''
  • truthy : tous les autres

Tous ? En JavaScript oui. Mais lorsqu'on se trouve côté client (donc avec l'objet window en plus), il y a un intru dans le DOM qui résiste à la norme. Il s'agit de document.all.

Pourquoi ? Pour ne pas casser certains sites archaïque qui utilisaient cette propriété dépréciée afin de différencier Netscape de IE5.

Sources :

http://stackoverflow.com/questions/10350142/why-is-document-all-falsy/10394873#10394873 http://lists.w3.org/Archives/Public/public-script-coord/2009OctDec/0059.html https://bugzilla.mozilla.org/show_bug.cgi?id=248549

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment