On Apr 14, 2011, at 5:03 PM, John J. Barton wrote:
> On 11:59 AM, Kyle Simpson wrote:
>> Brendan, you've asked for other coding examples where I use the pattern of
>> some variable being `undefined` or not to trigger different behavior (that
>> is, to use the variable or not). Here's two more:
>
> Here are some examples from Firebug code:
>
> Lazy object construction. A pervasive pattern in our code.
>
> if (!context.eventsMonitored)
> context.eventsMonitored = [];
This example does not argue strongly for infix-? given how JS users already
write if-then (no else) or use || and &&, e.g.
!context.eventsMonitored && (context.eventsMonitored = []);
context.eventsMonitored || (context.eventsMonitored = []);
> Temp introduced because `undefined` come at depth:
> var htmlPanel = context.getPanel("html", true);
> var vars = htmlPanel ? htmlPanel.getInspectorVars() : null;
Why wouldn't you use && here?
> Another `undefined` at depth
> (state ? state.wasScrolledToBottom : "no prev state")
This is explicltly ?:, i.e., if-the-else. It can't be simplified to if-then.
Did you mean something else?
/be
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss