Skip to content

Instantly share code, notes, and snippets.

@shoupn
Created Jun 8, 2018
Embed
What would you like to do?
ES6 Classes
//this is the old way of creating a class using protypal inheritance.
//As you see this is somewhat cumbersome and difficult to follow
var Employee = function(){
};
//Assign the do work method to the Employee object.
Employee.prototype ={
doWork: function(){
return "complete";
}
}
//create a new employee using our Employee class.
var e = new Employee();
e.doWork();
//How does ES6 do this?
//look below. Just realize that they are doing the same thing,
//however ES6 has the syntactic sugar to make this much cleaner
class Employee{
doWork(){
return "more work being done";
}
}
var e2 = new Employee();
e2.doWork();
//much cleaner approach and has more of an object oriented feel. Muh feelz!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment