Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Why are you teaching about constructor functions?

I've been reading up and perfecting(lol) My JS skills, and found many articles warning about utilizing constructor functions in JavaScript.

While reading "The Two Pillars of JavaScript" (https://medium.com/javascript-scene/the-two-pillars-of-javascript-ee6f3281e7f3), Eric Elliot informs us that:

"If you’re creating constructor functions and inheriting from them, you haven’t learned JavaScript. It doesn’t matter if you’ve been doing it since 1995. You’re failing to take advantage of JavaScript’s most powerful capabilities."

In "Constructors Are Bad For JavaScript" (http://tsherif.wordpress.com/2013/08/04/constructors-are-bad-for-javascript/) Tarek Sharif also warns:

I feel like I spent many hours learning about a technique that is inherently flawed. If that time were focused on Prototypal Inheritance and Lambdas (The "Two Pillars" that make JavaScript so incredibly versatile as a language), I think My time would have been better spent and that I'd have begun with a much better understanding of how JavaScript works.

Thoughts? Questions? Counter-arguments?

1 Answer

Probably only the instructor can really answer why the course is structured that way.

However, I can offer my personal opinion on the open ended question of analyzing programming techniques and philosophies: there is not just one, single "correct" way to program.

The articles you cited make a lot of sense within their context (I'm also diving into purely functional JavaScript, lambdas, and recursion right now, and getting a lot out of it).

You shouldn't feel like you've wasted your time here though. Constructors and the classical object oriented paradigm are still extremely relevant. Because other peoples' JavaScript code will use them -- inevitably you'll need to understand, test, debug, or extend someone else's code at some point.

Furthermore, outside of JavaScript, you may be forced to use them, because they're common features in a number of other important programming languages, like Java. By learning the general concept here, you can apply it in other languages as well.

Well stated, Jesdavpet! I never thought to look at it in the way you put it here: "Constructors and the classical object oriented paradigm are still extremely relevant. Because other peoples' JavaScript code will use them -- inevitably you'll need to understand, test, debug, or extend someone else's code at some point."

You're right. I probably will have to fix someone else's broken code, and that broken code will likely contain constructor functions. You've changed how I feel about having learned how they work, because now I have the tools to work with them.

However, I still think that Lambdas (with closures) and Objects without Classes (and how prototypal inheritance works) should be taught here, perhaps in an advanced course, because irresponsible use of constructor functions and the dangers it represents when using the 'this' selector can break your applications.

I must say that in the context of the courses available here on Treehouse, learning just the basics of JavaScript can get you by. Using it to manipulate the DOM or mixing in vanilla with jQuery to communicate with the server, constructor functions make life easy. But that includes only the simplest of functionality, which a student is unlikely to encounter in an actual development environment at a real company in the real world.

Perhaps I should have structured My post as an opinion post, because I was really looking for opinions and viewpoints.