News for hackers. Stuff that matters.
Re:TypeScript Features to Avoid by austincheney on Thursday January 20, 2022 @08:22AM (#30008514)
> But before that there were countless competing models for creating objects or object factories.

Java and C# had object factories even though in those languages classes could not be avoided. People wanted classes because they could not figure how to program without them.

> To pretend…

Don’t use this or new in your code and suddenly a tremendous amount of your code is exposed as unnecessary superfluous vanity. That isn’t making the language into something else.

Re:TypeScript Features to Avoid by mikojan on Thursday January 20, 2022 @08:33AM (#30008645)
> Java and C# had object factories

Object factories were competing models (plural) for creating any object. A total replacement for classes and the like, not an augmentation.

Here's one such model:

  function createCar(spec) {
    const {speed} = spec;
  
    let position = 0;
  
    return Object.freeze({
      move() {
       position += speed;
      },
      get position() {
        return position;
      }
    });
  }
And so you'd find this or any other model or multiple competing models in the very same code base.

It sucked.

> Don’t use this or new in your code

You are going to be mutating the internal state of objects. Using this and new or not.