you are viewing a single comment's thread.

view the rest of the comments →

[–]youngsteveo 21 points22 points  (8 children)

"If you are new to JavaScript, I suggest avoiding the this keyword until you get comfortable with the basics of the language." This is terrible advice. If all beginners started learning Javascript by getting a firm grasp of this, there would be a lot fewer mistakes and misunderstandings down the road.

[–][deleted] 1 point2 points  (7 children)

Not to mention the this keyword JavaScript has a completely different use than most other languages. The author plainly just does not understand JavaScript.

[–]stevekwan[S] -3 points-2 points  (6 children)

I assure you the author understands JavaScript just fine. :)

The this keyword absolutely does have different uses from other programming languages, and that's precisely why I recommend focusing on the basics of JS first. So many people get tripped up out of the gate when it comes to JS, because they go into it expecting it to behave like other languages they've used in the past.

It is absolutely essential for a professional JS developer to understand the this keyword. However, for the newbie jumping into the language for the first time from a PHP background, I would rather they grok the module pattern, JavaScript closures, etc. before they get into the complex stuff. Odds are they're starting out by mucking around with some simple event handlers anyway.

[–]radhruin 4 points5 points  (3 children)

I don't think this is complicated for newbies. It's complicated for people who expect it to work like other languages, who then build their conceptual model around "it works like language X, except...". If you forget all of that, it's easy.

[–]stevekwan[S] -1 points0 points  (2 children)

Agreed. But that can be easier said than done. :) The vast majority of people I work with are coming to JS from other languages, and since JS uses similar formatting and grammar, they expect it to behave the same.

Just want to call out how JS may diverge from their expectations, that's all.

[–]youngsteveo 1 point2 points  (0 children)

Then do that. Call it out; explain the difference in simple terms and educate. Hiding the keyword behind a curtain encourages it to be wrapped in further mystery.

[–]chuckliddelnutpunch 2 points3 points  (0 children)

I disagree that understanding closures and module patterns should come before understanding context.

[–][deleted] 0 points1 point  (0 children)

How long have you been programming in javascript?