Skip to content

Instantly share code, notes, and snippets.

@nodlAndHodl
Created June 8, 2018 18:49
Show Gist options
  • Save nodlAndHodl/d5fa69ec81239a714ded3c17184f7164 to your computer and use it in GitHub Desktop.
Save nodlAndHodl/d5fa69ec81239a714ded3c17184f7164 to your computer and use it in GitHub Desktop.
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