ricardofbarros / linter-js-standard

Atom linter plugin for JavaScript, using JavaScript Standard Style
https://atom.io/packages/linter-js-standard
MIT License
99 stars 48 forks source link

Destructing params in functions / constructors #202

Closed Eldar-X closed 7 years ago

Eldar-X commented 7 years ago

I got error message "args is not defined" when try to make this module.exports = class People { constructor ({name, age = 0} = args) { this.name = name this.age = age } }

Even when i set parser (babel-eslint / esprima) in package.json i don't see any changes

Arcanemagus commented 7 years ago

Destructuring can only be used where data is "received", primarily the left hand side of an assignment. You can use destructuring by simply doing constructor ({name, age = 0}) which, when fed an Object that has properties of .name and .age (defaulting to 0) it will create variables of those names. I'm assuming that's what you were aiming for here?

What you have written right now is likely being interpreted as a destructuring assignment like above, but with a default value of args (which isn't defined).

This has nothing to do with standard, or linter-js-standard though 😛, other than them telling you about this bug.

Eldar-X commented 7 years ago

you are right it's my bad 😃