You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NaN/undefined/Infinity should be matched as bindings rather than static values #317
functionpathological(x,undefined,NaN,Infinity){returnmatch(x){whenundefined: "undefined";
when NaN: "NaN";when Infinity: "Infinity";}}
Such bizarre bindings are honored elsewhere in the language (e.g., (NaN => [][NaN])("length") evaluates to 0 rather than undefined) and I believe discouraging the pattern via linters etc. is better than trumping explicit developer intent in match contexts where they are overridden.
Can you provide concrete examples of when this is actually intended by a developer? I can't say i've ever seen any (except that I've used undefined specifically to ensure it's the literal undefined)
They are, now, matched like that per the README (they're just handled by the Variable Matcher section), but I'm not sure exactly what the spec PR currently says. I don't have a strong opinion either way.
I think that their ability to be bindings is a flaw in the language, and unless there's compelling evidence presented that developers ever actually want this behavior, this is an elegant opportunity to avoid furthering the mistake.
I strongly disagree that "avoid furthering the mistake [in just this one construct]" would be an improvement: #293 (comment)
I'm just very sensitive to these kinds of epicycles—it's better IMO for the language to be consistently weird in having shadowable undefined/NaN/Infinity than for them to be shadowable in some contexts but not in others.
Activity
ljharb commentedon Mar 18, 2024
Can you provide concrete examples of when this is actually intended by a developer? I can't say i've ever seen any (except that I've used
undefinedspecifically to ensure it's the literalundefined)tabatkins commentedon Mar 18, 2024
They are, now, matched like that per the README (they're just handled by the Variable Matcher section), but I'm not sure exactly what the spec PR currently says. I don't have a strong opinion either way.
ljharb commentedon Mar 18, 2024
I think that their ability to be bindings is a flaw in the language, and unless there's compelling evidence presented that developers ever actually want this behavior, this is an elegant opportunity to avoid furthering the mistake.
gibson042 commentedon Mar 18, 2024
I strongly disagree that "avoid furthering the mistake [in just this one construct]" would be an improvement: #293 (comment)