-4

Will it still be evil and headbangingly frustrating and quirky like the others so far? When are they just going to get with the program, or will they ever? Personally, I hope they don't so that people abandon them for free software sooner, and that way I can use a shorter test:

var addEventListener = !-[1,] ? "attachEvent" : "addEventListener"; instead of testing for the methods themselves each time. Or will IE10 support both?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
wwaawaw
  • 6,867
  • 9
  • 32
  • 42

1 Answers1

1

IE9 uses addEventListener.
IE8 used XMLHttpRequest.

By trying to test for "IE-quirks" and then programming around that, you're missing the ability to actually use standard functionality.
Especially when the quirks you test for have nothing to do with the features you want to use. It doesn't matter if some of the browsers which have those quirks also don't have support for one standard feature or another...
Because some other browsers don't have the quirk, and don't have the feature...
...or do have the feature and still have the quirk.

Norguard
  • 26,167
  • 5
  • 41
  • 49
  • Who cares if standard functionality is *used* or not? I doubt its any more performant. So who cares, since my code is already cluttered with the feature checking (the only thing I care about) either way, what code is actually "executed"? – wwaawaw Oct 03 '12 at 02:35
  • Also, realistically speaking, it lines up pretty good, doesn't it? I mean, you can take it really far and test for *both* `attachEvent` *and* `detachEvent`. You see what I mean? – wwaawaw Oct 03 '12 at 02:36
  • But that's what I mean... ...if you're going to do tests where you check the length of an array for an added element, as a means to decide whether to use XHR, then you're forcing IE9 to use an AJAX library which hasn't been updated for browsers since IE6. It's safe to say that there's performance potential there. And why is your code littered? Create a single shim, and use that. A handful of lines would cover event-handling and AJAX, tested once apiece, and using the most-standard/performant versions possible. – Norguard Oct 03 '12 at 02:51
  • And using `addEventListener` to test for both `attachEvent` and `detachEvent` is all well and good - testing to see if [1,] is one array element or two, and using that to decide which event-system and AJAX system to use is another. But checking for addEventListener and then setting the value of `window.addEventListener` to a function which wraps `attachEvent`, passing in the proper `this` reference and passing `e` as the first parameter is a pretty straightforward process, and only needs to happen once, ever. – Norguard Oct 03 '12 at 02:53
  • I don't know where the AjAX talk came from -- this is only for event handling. I'm writing my shim right now. Do you have an answer to the actual question, though? – wwaawaw Oct 03 '12 at 03:33
  • Is `var addEventListener = document.createElement('a').attachEvent ? 'attachEvent' : 'addEventListener';` a reasonable approach? – wwaawaw Oct 03 '12 at 03:34
  • 2
    Well, the AJAX is equally-simple -- `XMLHttpRequest` vs `ActiveXObject msxml2.xmlhttp.3.0`. As for attacking the events... not really. Look for `.addEventListener` on the `window` object. If it doesn't exist, then swap into the creation of your backup. – Norguard Oct 03 '12 at 05:07