> ((person2||{}).address||{}).zip || "no zip");
>
Actually this takes the place of code like this:
(person2 && person2.address && person2.address.zip) ? person2.address.zip :
"no zip";
You can also use an if statement if you want.
> Does the code lose readability when done with that sort of shorthand?
> Also, is there the possibility of a performance hit for creating
> multiple empty objects?
>
I don't think it should impact the performance of the code in this case. You
will create all of the empty objects in the worst case scenario, and while
created and not referenced, the objects will be garbage collected anyway.
It's a bit unreadable imo, but it works.
--
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]