Skip to content

Conversation

@markangelillo
Copy link

Object.assign needs the first parameter to be the target, so it should be an empty object in this case.

Run this sample code to see the issue:

class MyClass {
  constructor(options = {}) {
    this.options = Object.assign(MyClass.defaultOptions, options);
    this.staticProperty = options.staticProperty;
  }
}
MyClass.defaultOptions = {
    staticProperty: 'classDefault',
    anotherProperty: 'anotherDefault',
};

let a = new MyClass({staticProperty: 'classA'});
console.log(MyClass.defaultOptions);
let b = new MyClass({staticProperty: 'classB'});
console.log(MyClass.defaultOptions);

Needs the target parameter to be an empty object.
Needs the target parameter to be an empty object.
Don't overwrite default options while making a copy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant