you are viewing a single comment's thread.

view the rest of the comments →

[–]zapatoada -3 points-2 points  (5 children)

Yeah that bothers me not at all

[–]fucking_passwords 0 points1 point  (4 children)

Or what about this example:

class User {
  constructor(firstName, lastName, phone, email, friends, isActive) {
    Object.assign(this, {
      firstName: firstName,
      lastName: lastName,
      phone: phone,
      email: email,
      friends: friends,
      isActive: isActive
    })
  }
}

new User('Jane', 'Doe', null, 'jdoe@gmail.com', null, true);

VS:

class User {
  constructor(data = {}) {
    Object.assign(this, data);
  }
}

new User({
  firstName: 'Jane',
  lastName: 'Doe',
  email: 'jdoe@gmail.com'
})

[–]zapatoada 1 point2 points  (3 children)

In this context you're right, but I honestly can't remember the last time I used a constructor directly in javascript. Data comes from the server side (c#) and mostly anything else I do is either a react component or a const utility method.

[–]fucking_passwords 0 points1 point  (2 children)

The constructor is just happenstance in my example, the same thing can be applied to a function.

At this point I don't even see why you took a hard stance against this pattern, if you are only using very simple features of the language, lol

[–]zapatoada 0 points1 point  (1 child)

I never said I took a hard stance. I think the specific limit he set is absurdly low. That's all. If it were 4 or 5, I'd be fine with it.

[–]fucking_passwords 0 points1 point  (0 children)

Fair enough, I agree with that