0

Originally I had it as, the error was that c was undefined.

constructor(c){
        this.x = c.x || 0;
        this.y = c.y || 0;
        ...
}

I tried doing this as well (as suggested by the answer to this question), the error is that the values always get set to default.

constructor({
        x = 0,
        y = 0
        } = {}){
        this.x = x;
        this.y = y;
        ...
}

Link to Github repo

2
  • So you need to test if c is an object before you read its property Question is, why would you pass in undefined to it and not with a default empty object. Commented Sep 2, 2021 at 0:23
  • this.x = c?.x || 0; or set a default for c Commented Sep 2, 2021 at 0:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.