Quote:
Originally Posted by goofyballer
I forget how I found myself watching a Crockford talk on Youtube one day, but he was talking about how he doesn't use new anymore (he doesn't have to, because he doesn't use "this" anymore, and also doesn't use Object.assign()? idk how he makes objects or what he does with them) and people who use the new class features in JavaScript will "never know how miserable they are."
He's right! I don't get why that's bad. I'm open to reading more on the topic to try to understand.
He explains it in that talk, I think. If you give me something you think you need a class for I'll rewrite it in crockford style. The problem is that within a framework like react that is buying into those features (they didn't have to, but they chose to), you're fighting an uphill battle to write in the crockford style. But for your domain objects you absolutely can.
You definitely shouldn't use "new". You can take any ordinary js constructor function intended to be used with new and add this as the first line inside the function body:
Code:
if (!(this instanceof NameOfYourFunction))
return new NameOfYourFunction(arg);
which will allow you to call it without using "new" but it will do the same thing.
As for "this", I think that's more a matter of taste.
The crucial thing is that your objects are immutable and you don't use implementation inheritance. As long as you're doing that, the rest is basically a taste war. Which is fine. But not really important.