Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I always include something around `this` behaviour in my interviews if the position is Javascript related. You cannot possibly have a decent experience in JS without have been bit by this.

And I'm always amazed by the amount of developers that just do not understand how it works, and bind every possible methods.



Anyone who claims to know JS and doesn't have "this" down cold is either a disaster waiting to happen, or a disaster in progress.


Sorry, but the semantics of "this" in JavaScript are crazy — and I think that's being generous. There are a few common use cases that trip people up, e.g., situations where "this" becomes bound to another object like the global window object, and I'd expect an experienced JavaScript programmer to know those.

It depends on what you mean by "down cold," obviously, but if your standard is "either they have the semantics of the 'this' keyword down cold or they're incompetent" then virtually all JavaScript programmers I know (including myself) are incompetent.


Now, hold on there. These "anyone who" statements chafe me; like the junior dev who exclaimed "anyone who doesn't write unit tests shouldn't call themselves an engineer" in a meeting filled with people 15 years his senior who had collectively shipped far, far more successful software than him, without writing tests.

Several years ago, I led two different front-end web teams at a large, well-known company. I wrote a lot of JavaScript then. In fact, I wrote the core JS framework for one of the apps. I probably understood "this" at that time. I couldn't begin to tell you now, because I've been working on hit iOS games since - probably without knowing a lot of the nuances of Obj-C at times! There was no disaster back then - we shipped high-quality sites on time. There would be no disaster now, because if I went back to JS I'd crack a book.

The most important skills I bring to any project are a lot higher-level than the details of a particular language. I haven't made my career on one language or platform, but dozens of them. For the details, I work with reference material handy. After a month, I probably have a good grasp of whatever I'm working with. A year after that project, I probably don't, but I could bring it back easily.


That's cool. But don't write JS if you don't know what this does, because it will bite you.


Or just avoid using `this` unless you're sure about what it does in a particular context.


Or just learn what 'this' means because, seriously, you're a programmer and it's not that hard to figure out.


That means that every person who reads your code also must understand "this" correctly in order to interpret your code correctly.

In certain team environments, I avoid 'this' because the programmer who is looking at this file next may not understand it's proper usage.


Come on, there are what, half a dozen keywords in JavaScript? It's not that complicated.


It's only upon reflecting upon "this" recently that I realized that it is (effectively) a global (thread-local) variable set by the X.Y() syntax. (I mean, I understood to be the case, but I just didn't realize the impliciations for understanding "this".)

The ECMAScript committe are taking steps to make "this" more useful, but the current semantic is so insane that I don't it's particularly surprising that people who aren't language lawyers don't understand it.

(*) Given that Javascript uses a single-threaded model.


Likewise, I ask it also. When someone has spent the last 3 years as a "JavaScript developer" and doesn't have a basic grasp of context in JS, them it's a red flag.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: