Skip to content

Comment on Stop Using Constructors in JS (2012)

Comments

Timeline of learning JavaScript

1. Constructer's are great it's just like language x

2. uncanny valley of realizing it's not actually like language x

3. understanding constructors, use them everywhere

4. get burned by subtler points of this in async functions and forgetting new, decide to go all functional all the time

5. have enough experience to avoid the foot guns, use constructors all the time as they tend to be the fastest method and have the best support.

This article is at stage 4

It's not async functions, it's first class functions. Having multiple ways of calling a function doesn't compose. I have enough experience to know where the foot guns are at, but I don't like writing code that has foot guns in them. It's like `null` in Java. "Remember to check for null before using every object". "Remember to use new before every function that instantiates an object.". I'd rather programmers quit creating new classes of errors in languages for 'programmer convenience'.

Object creation has not yet caused my any performance issues, so I've not seen a reason to personally use `new`.

6. Be Douglas Crockford. http://www.youtube.com/watch?v=bo36MrBfTk4&t=19m

I believe he has some experience of JS.

Argument From Cranky Authority (Whose Lawn You Are On)

Possibly, but it does rather blow a hole in the argument that only people with limited experience in JS would treat `new` as a footgun.

I'm not a JS guy, but when I read articles about Python or VIM here on HN I often want to write comments like yours. I still have a hard time accepting that after 5 the number 6 will probably be much closer to 4 again, just with more nuances.

Number 6 would probably be confidence in when it's not a performance bottleneck to not use constructors some of the time.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.