On Tue, Feb 15, 2011 at 3:18 PM, Angus Croll <[email protected]> wrote: > Hi Dmitry > > Oliver Steele's version is cute - but maybe too cute for production > code (not so readable) > > I would probably do this; > > person2 && person2.address && (person2.address.zip || 'no zip'); > > (the 'if' just adds visual pollution IMO) > > ...but the exception trick is neat too. Regarding your question, > exceptions add a slight performance overhead so be careful not to use > too often if performance is really an issue. Having said that I think > some authors exaggerate their performance impact. > > Angus > > On Feb 15, 6:04 am, Dmitry Pashkevich <[email protected]> wrote: >> I am not very savvy in using exceptions... Are there any pitfalls with their >> use in such case? > > -- > To view archived discussions from the original JSMentors Mailman list: > http://www.mail-archive.com/[email protected]/ > > To search via a non-Google archive, visit here: > http://www.mail-archive.com/[email protected]/ > > To unsubscribe from this group, send email to > [email protected] >
Angus, that's the one I prefer for such extreme cases, still readable and short... The try/catch bit is nothing more than a trick but it really blur things for the reader (in the mentioned case) and as stated it may add unnecessary overhead if used in the inners of a library method called several times or in "mousemove" (or similar) event handlers. @Sam Merrell don't take extra optimization paths, in your case "person2" is a repeated pattern and the minification/compression will already handle that shortening for you and probably do better. -- Diego -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ To unsubscribe from this group, send email to [email protected]
