Originally Posted by Philip M
I am not at all sure why your or rnd me's solutions (which are, of course, perfectly valid) are supposed to "better" or "real world". As we often say, there is more than one way to skin a cat.
While many people are still using older browsers, it is pointless to code in such a way that it works only in browsers which support HTML5. In a few year's time - perhaps.
1. i usually go by K.I.S.S, Occam's razor, etc. JS often rewards simple code with fast execution. i think my code is dead-simple to read: you name a function, regexp's test() method, and you name the property to test for, and it returns a new list of the list items passing your specifications. How it gets any simpler than that, i can't imagine. i don't think introducing variables where they need not be used reduces complexity. In CS terms, variables and loops adds complexity...
2. i would argue that it's certainly not pointless to the 90% of devices that my code runs upon out-of-the-box. if you wait a few years to start implementing "HTML5" (whatever that even means), you are going to get impossibly behind; we are over the hump of the roller coaster, rapidly accelerating as we descend. i'm constantly struggling to keep up, at least since this summer. when it rains, it pours.
Some of the new stuff is complicated (indexeddb, webRTC, webAudioAPI, DnD, etc), and some of it is dead-simple (localStorage, classList, dataset, cors, html5 form attribs, typedArrays, FileReader, etc). The complicated stuff is still up in the air, but at least 75% of the simple stuff is available to 75% of surfers off the shelf, and 75% of the rest can be poly-filled. that's being conservative btw.
Now that IE is live-updated, it's game over, we're circling in on virtual perfection, not spinning off on wild one-browser tangents like we were just a couple years ago. refer to caniuse; it's doesn't appear to me that much else of anything worth a $%$# is going to enter the pipe not next year, or the year after that, but 2 years? that's crazy talk. M$ may change their mind about a few things here and there, and i hope they do on RTC codecs, but most of the cats are out of the bag.
The species that thrive in the long run are not the strongest, fastest, or smartest; they are the creatures most adaptable to change.