-
Notifications
You must be signed in to change notification settings - Fork 795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warn about accidentally destructuring to globals? #371
Comments
By the way, you do mention it can destructure to object properties and existing vars, in the penultimate par on page 97, but it would be great to mention that in the original explanation, too. |
Sorry, I'm not quite sure what you're asking here. Can you be more specific? |
Sorry I was unclear. Let me try again. Destructuring works in declarations ( Your example code for this chapter focuses on declaration scenarios.
function poorlyPickTwoProps (obj) {
{ foo, bar } = obj
return { foo, bar }
} (yes, this would be much more nicely done by destructuring in the sig, bear with me 😉) Here, we unwittingly introduce two globals: Is that clearer, or am I botching this again? 🤔 |
Hi Nicholas,
Location: Chapter 5 > Page 86 > "Destructuring Assignment" > first code block
Your examples all use destructuring in assigments (
let
orconst
), but it's also possible towards object properties, e.g.:And, more dangerously, seems to retain JS' long-standing wart of "accidentally" declaring globals when using hitherto-unknown identifiers without a declaration keyword ahead of them (agreed, strict mode would kill this, but we're not always in strict mode, unfortunately).
Do you think this would be a good warning to add somewhere in there?
The text was updated successfully, but these errors were encountered: