|
On May 18, 2014 1:07 PM, "Andrew Starks" <andrew.starks@trms.com> wrote:
> On Sunday, May 18, 2014, Jay Carlson <nop@nop.com> wrote:
>>
>> On May 18, 2014 12:05 PM, "Andrew Starks" <andrew.starks@trms.com> wrote:
>>
>> > However, if anything were to be done, it must make things clearer. So, which is clearer to you:
>> >
>> > ```
>> > --Do we have have an item, with a background color?
>> > if not (document.body.item
>> > and document.body.item.style
>> > and document.body.item.style.backgroundColor) then
>> > ....
>> > end
>> >
>> >
>> > --or (accepting alternate forms of the OP's style (|?.| or what have you)
>> >
>> > if not document.body?item?style?backgroundColor then
>> > ...
>> >
>> > end
>>
>> What's inside the body of the "if"?
>
>
> Don't set the background color? The example is completely contrived. If the use cases aren't obvious, then it's fair to ask for real examples. But, I'm not sure I follow the question.
I ask because I rarely see deeply nested tests of attribute presence without making use of the the path navigating to the attribute. Without written-out examples I worry this is trying to write:
if not document.body?item?style?backgroundColor then
return
end
repaint(document.body.item.style.backgroundColor)
Better to write:
local bg = document.body?item?style?backgroundColor
if not bg then
return
end
repaint(bg)
Jay