There are nine units in Lambda School’s Full Stack Web Development Pre-course. I’m going to summarize what the pre-course covers for each of them. This material is basically ground-floor information that students need to know before they start the full course.

Classes
A class, in JavaScript, is a type of function. From reading on the internet, I’ve learned that classes don’t offer any new functionality beyond what objects and object prototypes already do; what they do is provide a cleaner way to write objects or functions. Their syntax makes it easier for programmers who are versed in other languages to move to JavaScript, since its more straightforward than older methods of working with objects prior to ES6, the big JavaScript/ECMAScript update from 2015.
This is an example of creating a function in JavaScript. Its composed of the keyword function, the name of the function, opening and closing parenthesis, and opening and closing brackets:
function screamsInJS() {}
This is an example of creating a class in JavaScript. Its basically the same as creating a function, but without the parenthesis (class keyword, class name, brackets):
class zodiacSign {}
These two fantastic articles by Tania Rascia and Majid Hussain, respectively, provide a clear description of JavaScript classes and insight into how classes differ from functions and prototypes:
As per the Lambda School text:
Often times when we create an object, we are creating a template. Rather than copy that template over and over again, Javascript gives us access to what we call a constructor or class. Classes share much of the same functionality as regular objects, but also expands on that functionality greatly. Classes are useful for creating many objects that share some of the same properties and methods (such as users on a website).
Class and Pseudo Classical Instantiation
I can understand how to use classes in JavaScript on a very basic level. What makes my head spin is trying to comprehend how its different from other programming languages. I don’t quite grasp the difference yet, but apparently, JavaScript’s implementation of classes is not the same as classes in other object-oriented programming languages, like Java and C++. The little I was able to get makes them seem the same to me – in both cases, classes are blueprints or templates for creating objects, and there’s something to do with inheritance, which is some kind of passing down of permissions or states to an object from whatever created it. Maybe later on in the full Lambda course, it’ll become clearer.
The following article makes a case for using objects or functions in place of classes in JavaScript. Its an interesting read, as it discusses the differences and similarities between each of those items:
From the Medium article:
A class is a blueprint for creating objects. We define what properties and methods an object should have, which taken together are considered a type, and then instantiate many objects using that blueprint. Perhaps a more visual analogy is that a class acts as an object creation factory.
As per the Lambda School text:
If you have experience in an Object Oriented language (such as Java or C#) you are probably familiar with the concept of classes. While Javascript does not provide a ‘true’ class system, there is something very familiar. For the sake of argument we will call our class objects ‘classes’. It is instantiated in a Pseudo Classical way, using the new keyword, and can take arguments.
The above text from Lambda also makes the claim that JavaScript’s implementation of classes isn’t a true class system, compared to other object-oriented programming languages. It, too, doesn’t really explain why.
Here’s a thread from Reddit that discusses class in JavaScript and compares it to other languages’ implementations without using terminology or concepts that I can follow yet. It does look like common parlance will refer to classes in JavaScript as classes, however, and computer scientists will refer to them as something else, like maybe a class object or ES6 class:
As per the Lambda School text:
In this example we will be creating a Cat class. Convention for classes is to give the name of anything that can be instantiated with the new keyword an uppercase name. When we use the new keyword, Javascript does some great behind the scenes work for us and creates and returns an object automatically.
I think that the “great behind the scenes work” that the above text refers to is using a constructor to build an object or class. I’m a little unclear about what that all entails, but most of the websites that I’ve read which discuss classes in JavaScript give examples that make use of a constructor inside of the class to create objects. It seems that if a constructor is left out, JavaScript automatically adds an invisible one with no parameters to the class. Once I find out more about this, I’ll post.
function Cat(name) {
// the 'new' operator creates an object, ‘this’
this.name = name;
this.meows = function() {
return ‘My name is ’ + this.name + ’ …Meow!’;
}
// return the object ‘this’
}
const sam = new Cat('Sam');
const kitty = new Cat('Kitty');
console.log(sam.meows()); // 'My name is Sam ...Meow!'
console.log(kitty.meows()); // 'My name is Kitty ...Meow!'
‘this’ in Classes
As per the Lambda School text:
The this keyword can start to become very confusing when we start using it in classes. In the last example we use it in the meows method. A good rule of thumb if you are not certain what this is referring to, is to look at where the method is called, and the object to the left of the ‘dot’. That is the object this refers to.
So far, “this” hasn’t been a problem for me to use. I’ve only used it inside of a method or class, but it seems fairly straightforward at this stage that it simply refers to the object that its used inside of. I understand that it gets more complicated later on, but we’ll cross that bridge when we get there.
One thought on “Lambda School Pre-course 20: Learn to use classes, demonstrate when to use them and write and use ES5 class syntax”