Prev: Standalone .js file creates IE, and call javascript functions in the page
Next: Javascript pause or sleep thread execution
From: Garrett Smith on 12 Dec 2009 04:18 Austin Matzko wrote: > On Dec 11, 9:05 pm, Thomas 'PointedEars' Lahn <PointedE...(a)web.de> > wrote: >>>> e = e || window.event; >> Reasonable people use an `if' statement here instead. > > Would you please elaborate? I'm curious why an "if" statement would > be better. > Yes, what is unreasonable about that? > The statement "e = e || window.event" appears in a > comp.lang.javascript FAQ example: <http://www.jibbering.com/faq/ > #FAQ4_26> So it does! I like this idiom because it is more concise. I would like it even better as:- // Invalid syntax. This code will result in error. e ||= window.event; But alas, no such ||= operator. About the closest I can getis e = e || window.event; How did you arrive at the URL you posted? The FAQ itself links to: http://jibbering.com/faq/#detectBrowser -- Garrett comp.lang.javascript FAQ: http://jibbering.com/faq/
From: JR on 12 Dec 2009 08:05 On Dec 12, 3:25 am, Stefan Weiss <krewech...(a)gmail.com> wrote: > On 12/12/09 04:05, Thomas 'PointedEars' Lahn wrote: > > > Then again, responsible developers would not try this whole nonsense in the first place. > ... > > No, what you *need* is a dosage of common sense. Leave *my* keyboard alone! > > Exactly! Thank you, that needed to be said. > > I use Ctrl a *lot*. I use it to operate my browser, to scroll the page, > to copy and paste text, etc. If I saw a site where ctrl triggered a > JavaScript alert, I would automatically mentally file it as evil / scum > / target for abuse. At the very least, I'd add it to my list of blocked > sites. If I'm bored I might have a look around and see what else looked > broken. It's not very clever to annoy your guests. Why people always tend to generalize particular cases in c.l.js? Who said the CTRL key should be blocked in the whole site. What if it's done in a specific page for an intranet app? -- JR
From: JR on 12 Dec 2009 08:21 On Dec 12, 1:05 am, Thomas 'PointedEars' Lahn <PointedE...(a)web.de> wrote: > Krist wrote: > > On 12 Des, 03:21, JR <groups_j...(a)yahoo.com.br> wrote: > >> document.onkeydown = keyCheck; > > Responsible developers feature-test host object's properties instead, and > use this only as a fallback for the standards-compliant approach. Feature-test document in a web browser? It seems to be a naive advice... > >> function keyCheck(e) { > > Reasonable people use a function expression here instead. Is it really necessary or an alternative? > >> e = e || window.event; > > Reasonable people use an `if' statement here instead. You must be kidding. > >> if (e.ctrlKey) { > > Responsible developers feature-test host object's properties before they are > accessing them in a type-converting test. Then again, responsible > developers would not try this whole nonsense in the first place. > > >> alert("CTRL key is not allowed"); > > window.alert(...); > > but neither should not be used here. > > >> } > >> } > >> </script> > > >> Cheers, > >> [...] > > > Thanks JR, > > That is what I need. > > No, what you *need* is a dosage of common sense. You should look at the man in the mirror because it applies to him too. > > God bless you > > Said the blind led by the blind. Poor thing! Thomas was feeling blue because no one thanked him first.
From: Thomas 'PointedEars' Lahn on 12 Dec 2009 17:09 Austin Matzko wrote: > Thomas 'PointedEars' Lahn wrote: >> >> e = e || window.event; >> >> Reasonable people use an `if' statement here instead. > > Would you please elaborate? I'm curious why an "if" statement would > be better. It saves one needless evaluation step, and because it allows for a block statement it allows for a finer control, including proper feature-testing. > The statement "e = e || window.event" appears in a > comp.lang.javascript FAQ example: <http://www.jibbering.com/faq/ > #FAQ4_26> That's a bug. PointedEars -- var bugRiddenCrashPronePieceOfJunk = ( navigator.userAgent.indexOf('MSIE 5') != -1 && navigator.userAgent.indexOf('Mac') != -1 ) // Plone, register_function.js:16
From: Asen Bozhilov on 12 Dec 2009 17:53
Thomas 'PointedEars' Lahn wrote: > It saves one needless evaluation step What is the difference between: var foo = 0 || 1; //1 AND var foo; if (0) { foo = 0; } else { foo = 1; } In concrete case which discussed here, you are absolutely right. But in general plan i don't see any difference. If you see, please explain. Regards. |