3 ms·
I've never understood: if(typeof document.attachEvent !== undefined) document.attachEvent(...) wouldn't if(typeof document.attachEvent == 'function') be much
by iamleppert 15y ago
I've never understood:
if(typeof document.attachEvent !== undefined)
document.attachEvent(...)
wouldn't
if(typeof document.attachEvent == 'function') be much better?
that way you assure it's actually something that's actually callable?
- ufo 15y agoTo be fair, if attachEvent exists and is not a functions then some deep shit must be going on. In the first case you at least get an error to tell you about it. But in general I prefer to use `'prop' in obj` instead of testing `obj.prop` for undefined. Some methods in IE browser objects have funky getters that sometime throw exceptions if you try to read them so using `in` is safer.