r/javascript • • Feb 23 '13

Common JavaScript "Gotchas"

https://github.com/stevekwan/best-practices/blob/master/javascript/gotchas.md
16 Upvotes

50 comments sorted by

View all comments

20

u/youngsteveo Feb 23 '13

"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.

2

u/[deleted] Feb 23 '13

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

-2

u/stevekwan Feb 23 '13

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.

3

u/chuckliddelnutpunch Feb 24 '13

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