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 Asynchronous Programming with JavaScript Understanding Promises From Callbacks to Promises

Nicolas Valdivieso
Nicolas Valdivieso
6,654 Points

Why are constructors used in this video if they haven't even been introduced?

i personally know constructors bc i had previous experience but it makes me wonder what about the ppl that are joining this course with no previous experience on javascript.

No one should be taking a course like this without having a solid foundation in the basics. This course will be virtually useless to them without having experience.

5 Answers

Steven Parker
Steven Parker
229,732 Points

This is an intermediate level course, and is not a good starting place for anyone who has no previous experience in JavaScript.

Anyone learning JavaScript for the first time might find the Beginning JavaScript track to be a more suitable way to get started.

Robert O'Toole
Robert O'Toole
6,366 Points

i still don't think ive ever been introduced to constructors in the front end track. luckily i know what they are but there seems to be a big jump in expected knowledge at this point even after taking the beginner courses in front end.

I just had a look at the FEWD track. It looks like the course Object-Oriented JavaScript actually comes after courses on AJAX and Asynchronous Programming, which is a major oversight. Object Oriented programming is a particular way, or paradigm for programming in which the major components of a program are composed of objects, which have methods (functions attached to the object) and properties (variables encapsulated in the object). A lot of the things you're working with in asynchronous programming, like the XMLHttpRequest object and promises are objects. Objects are made out of classes, which are like blueprints that can generate as many instances as you want, you simply use the constructor for the class. E.g:

class Cat 
{
    constructor(name) 
    {
        this.name = name;
    }

    sayHello() 
    {
        console.log(`Meow, my name is ${this.name});
    }
}

const fuzzy = new Cat('Fuzzy');

fuzzy.sayHello();
// Meow, my name is Fuzzy

This is just a really basic tutorial. You should probably take the Object-Oriented JavaScript course and then the Object-Oriented JavaScript: Challenge course before doing anything else. These two courses will definitely challenge you, but take it at a comfortable speed and be patient. At the end you will have leveled up as a developer.

You might also want to let the Treehouse staff know about the OOP not being taught at the correct point in the track. Good luck!

My last comment might not have made one point clear. The constructor is the function you call to instantiate a class, or in other words, create an object from the class. And again, the class is a blue print for the object. So you write:

new Cat('Fuzzy');

The new keyword lets JavaScript know you're making a new object from the class. You can do this with things like arrays, for instance. Arrays are just a kind of object. Usually people use array-literals [1, 2, 3] but you could write:

const myArray = new Array(1, 2, 3);

myArray;
// [1, 2, 3]

Everything in JavaScript pretty much is an object and can be worked with in this sort of way, though for a long of things its not convenient and literals work better.

Jamie Moore
Jamie Moore
3,997 Points

I thought I was just being a bit dumb by not understanding what's going on in this lesson. I've been following the 'full stack web development' track and constructors definitely haven't been introduced yet. Neither has anything related to running node in the terminal.

Roald Jurrian Kamman
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Roald Jurrian Kamman
Front End Web Development Techdegree Graduate 15,543 Points

Thank you Michael Cook for pointing that out! I was struggling with all the strange syntax and some other things I can't really define because I haven't seen them before. It makes sense that I'm missing a piece. Will put this on hold until I'm finished with the object-oriented javascript.

In the Fullstack Techdegree, they were introduced in the OOJS bit: https://teamtreehouse.com/library/objectoriented-javascript-2

Not sure about other courses though...! If you think there's a disconnect in the tracks/courses, you should provide that feedback to support.